use of io.asgardeo.java.oidc.sdk.bean.User in project asgardeo-java-oidc-sdk by asgardeo.
the class DefaultOIDCManager method handleSuccessTokenResponse.
private void handleSuccessTokenResponse(TokenResponse tokenResponse, SessionContext sessionContext, Nonce nonce) throws SSOAgentServerException {
AccessTokenResponse successResponse = tokenResponse.toSuccessResponse();
AccessToken accessToken = successResponse.getTokens().getAccessToken();
RefreshToken refreshToken = successResponse.getTokens().getRefreshToken();
String idToken;
try {
idToken = successResponse.getCustomParameters().get(SSOAgentConstants.ID_TOKEN).toString();
} catch (NullPointerException e) {
logger.log(Level.ERROR, "id_token is null.");
throw new SSOAgentServerException(SSOAgentConstants.ErrorMessages.ID_TOKEN_NULL.getMessage(), SSOAgentConstants.ErrorMessages.ID_TOKEN_NULL.getCode(), e);
}
try {
JWT idTokenJWT = JWTParser.parse(idToken);
IDTokenValidator idTokenValidator = new IDTokenValidator(oidcAgentConfig, idTokenJWT);
IDTokenClaimsSet claimsSet = idTokenValidator.validate(nonce);
User user = new User(claimsSet.getSubject().getValue(), getUserAttributes(idToken));
sessionContext.setIdToken(idTokenJWT.getParsedString());
sessionContext.setUser(user);
sessionContext.setAccessToken(accessToken.toJSONString());
if (refreshToken != null) {
sessionContext.setRefreshToken(refreshToken.getValue());
}
} catch (ParseException e) {
throw new SSOAgentServerException(SSOAgentConstants.ErrorMessages.ID_TOKEN_PARSE.getMessage(), SSOAgentConstants.ErrorMessages.ID_TOKEN_PARSE.getCode(), e);
}
}
Aggregations