Search in sources :

Example 1 with User

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);
    }
}
Also used : RefreshToken(com.nimbusds.oauth2.sdk.token.RefreshToken) User(io.asgardeo.java.oidc.sdk.bean.User) AccessToken(com.nimbusds.oauth2.sdk.token.AccessToken) JWT(com.nimbusds.jwt.JWT) SignedJWT(com.nimbusds.jwt.SignedJWT) SSOAgentServerException(io.asgardeo.java.oidc.sdk.exception.SSOAgentServerException) IDTokenClaimsSet(com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet) ParseException(java.text.ParseException) AccessTokenResponse(com.nimbusds.oauth2.sdk.AccessTokenResponse) IDTokenValidator(io.asgardeo.java.oidc.sdk.validators.IDTokenValidator)

Aggregations

JWT (com.nimbusds.jwt.JWT)1 SignedJWT (com.nimbusds.jwt.SignedJWT)1 AccessTokenResponse (com.nimbusds.oauth2.sdk.AccessTokenResponse)1 AccessToken (com.nimbusds.oauth2.sdk.token.AccessToken)1 RefreshToken (com.nimbusds.oauth2.sdk.token.RefreshToken)1 IDTokenClaimsSet (com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet)1 User (io.asgardeo.java.oidc.sdk.bean.User)1 SSOAgentServerException (io.asgardeo.java.oidc.sdk.exception.SSOAgentServerException)1 IDTokenValidator (io.asgardeo.java.oidc.sdk.validators.IDTokenValidator)1 ParseException (java.text.ParseException)1