SUPPORT-8427: Fix
This commit is contained in:
parent
bcf9721224
commit
b89b4a70c3
2 changed files with 13 additions and 10 deletions
|
|
@ -29,7 +29,7 @@ public class EsiaController {
|
|||
}
|
||||
|
||||
@RequestMapping(value = "/esia/auth", params = "code", method = RequestMethod.GET)
|
||||
public boolean esiaAuth(@RequestParam("code") String code, HttpServletResponse response) {
|
||||
public boolean esiaAuth(@RequestParam("code") String code, HttpServletRequest request, HttpServletResponse response) {
|
||||
return esiaAuthService.getEsiaTokensByCode(code, response);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public class EsiaAuthService {
|
|||
return uriBuilder.toString();
|
||||
}
|
||||
|
||||
public boolean getEsiaTokensByCode(String esiaAuthCode, HttpServletResponse response) {
|
||||
public boolean getEsiaTokensByCode(String esiaAuthCode, HttpServletRequest request, HttpServletResponse response) {
|
||||
try {
|
||||
String clientId = esiaConfig.getClientId();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss xx");
|
||||
|
|
@ -172,16 +172,18 @@ public class EsiaAuthService {
|
|||
if (tokenResponse != null && tokenResponse.getError() != null) {
|
||||
throw new RuntimeException(tokenResponse.getError_description());
|
||||
}
|
||||
String path = request.getContextPath();
|
||||
String accessToken = tokenResponse.getAccess_token();
|
||||
Cookie cookie = new Cookie("access_token", accessToken);
|
||||
cookie.setHttpOnly(true);
|
||||
cookie.setPath("/");
|
||||
cookie.setPath(path + "/");
|
||||
response.addCookie(cookie);
|
||||
|
||||
String refreshToken = tokenResponse.getRefresh_token();
|
||||
Cookie cookieRefresh = new Cookie("refresh_token", refreshToken);
|
||||
cookieRefresh.setHttpOnly(true);
|
||||
cookieRefresh.setPath("/");
|
||||
|
||||
cookieRefresh.setPath(path + "/");
|
||||
response.addCookie(cookieRefresh);
|
||||
|
||||
byte[] decodedBytes = Base64.getDecoder()
|
||||
|
|
@ -191,7 +193,7 @@ public class EsiaAuthService {
|
|||
EsiaAccessToken esiaAccessToken = objectMapper.readValue(decodedString, EsiaAccessToken.class);
|
||||
Token token = jwtTokenService.createAccessToken(esiaAccessToken.getSbj_id(), tokenResponse.getExpires_in());
|
||||
Cookie authToken = new Cookie("auth_token", token.getValue());
|
||||
authToken.setPath("/");
|
||||
authToken.setPath(path + "/");
|
||||
authToken.setHttpOnly(true);
|
||||
response.addCookie(authToken);
|
||||
SecurityContextHolder.getContext()
|
||||
|
|
@ -199,7 +201,7 @@ public class EsiaAuthService {
|
|||
new UsernamePasswordAuthenticationToken(esiaAccessToken.getSbj_id(), null));
|
||||
|
||||
Cookie isAuth = new Cookie("is_auth", "true");
|
||||
isAuth.setPath("/");
|
||||
isAuth.setPath(path + "/");
|
||||
response.addCookie(isAuth);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -265,13 +267,14 @@ public class EsiaAuthService {
|
|||
String accessToken = tokenResponse.getAccess_token();
|
||||
Cookie cookie = new Cookie("access_token", accessToken);
|
||||
cookie.setHttpOnly(true);
|
||||
cookie.setPath("/");
|
||||
String path = request.getContextPath();
|
||||
cookie.setPath(path + "/");
|
||||
response.addCookie(cookie);
|
||||
|
||||
String newRefreshToken = tokenResponse.getRefresh_token();
|
||||
Cookie cookieRefresh = new Cookie("refresh_token", newRefreshToken);
|
||||
cookieRefresh.setHttpOnly(true);
|
||||
cookieRefresh.setPath("/");
|
||||
cookieRefresh.setPath(path + "/");
|
||||
response.addCookie(cookieRefresh);
|
||||
|
||||
byte[] decodedBytes = Base64.getDecoder()
|
||||
|
|
@ -281,7 +284,7 @@ public class EsiaAuthService {
|
|||
EsiaAccessToken esiaAccessToken = objectMapper.readValue(decodedString, EsiaAccessToken.class);
|
||||
Token token = jwtTokenService.createAccessToken(esiaAccessToken.getSbj_id(), tokenResponse.getExpires_in());
|
||||
Cookie authToken = new Cookie("auth_token", token.getValue());
|
||||
authToken.setPath("/");
|
||||
authToken.setPath(path + "/");
|
||||
authToken.setHttpOnly(true);
|
||||
response.addCookie(authToken);
|
||||
SecurityContextHolder.getContext()
|
||||
|
|
@ -289,7 +292,7 @@ public class EsiaAuthService {
|
|||
new UsernamePasswordAuthenticationToken(esiaAccessToken.getSbj_id(), null));
|
||||
|
||||
Cookie isAuth = new Cookie("is_auth", "true");
|
||||
isAuth.setPath("/");
|
||||
isAuth.setPath(path + "/");
|
||||
response.addCookie(isAuth);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue