Search in sources :

Example 1 with ImmutableOAuthClientConfiguration

use of com.nexblocks.authguard.jwt.oauth.config.ImmutableOAuthClientConfiguration in project AuthGuard by AuthGuard.

the class OAuthService method getOrCreateAccount.

private AccountBO getOrCreateAccount(final OAuthServiceClient serviceClient, final String authorizationCode, final String idToken) {
    final ImmutableOAuthClientConfiguration configuration = serviceClient.getConfiguration();
    final DecodedJWT decoded = JWT.decode(idToken);
    final String externalId = decoded.getSubject();
    final Optional<AccountBO> account = accountsService.getByExternalId(externalId);
    if (account.isPresent()) {
        return account.get();
    }
    final AccountBO.Builder newAccount = AccountBO.builder().externalId(externalId).social(true).identityProvider(configuration.getProvider());
    if (configuration.getEmailField() != null) {
        final Claim emailClaim = decoded.getClaim(configuration.getEmailField());
        if (!emailClaim.isNull()) {
            newAccount.email(AccountEmailBO.builder().email(emailClaim.asString()).build());
        }
    }
    final RequestContextBO requestContext = RequestContextBO.builder().source(configuration.getProvider()).idempotentKey(authorizationCode).build();
    return accountsService.create(newAccount.build(), requestContext);
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Claim(com.auth0.jwt.interfaces.Claim) ImmutableOAuthClientConfiguration(com.nexblocks.authguard.jwt.oauth.config.ImmutableOAuthClientConfiguration)

Aggregations

Claim (com.auth0.jwt.interfaces.Claim)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 ImmutableOAuthClientConfiguration (com.nexblocks.authguard.jwt.oauth.config.ImmutableOAuthClientConfiguration)1 AccountBO (com.nexblocks.authguard.service.model.AccountBO)1 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)1