Search in sources :

Example 1 with IDTokenBuilder

use of org.wso2.carbon.identity.openidconnect.IDTokenBuilder in project identity-inbound-auth-oauth by wso2-extensions.

the class AccessTokenIssuerTest method getMockIDTokenBuilderForSuccess.

private IDTokenBuilder getMockIDTokenBuilderForSuccess() throws IdentityOAuth2Exception {
    IDTokenBuilder idTokenBuilder = mock(IDTokenBuilder.class);
    when(idTokenBuilder.buildIDToken(any(OAuthTokenReqMessageContext.class), any(OAuth2AccessTokenRespDTO.class))).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return ID_TOKEN;
        }
    });
    return idTokenBuilder;
}
Also used : IDTokenBuilder(org.wso2.carbon.identity.openidconnect.IDTokenBuilder) OAuth2AccessTokenRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 2 with IDTokenBuilder

use of org.wso2.carbon.identity.openidconnect.IDTokenBuilder in project identity-inbound-auth-oauth by wso2-extensions.

the class AccessTokenIssuerTest method setupOIDCScopeTest.

private void setupOIDCScopeTest(String grantType, boolean success) throws IdentityOAuth2Exception {
    AuthorizationGrantHandler grantHandler = getMockGrantHandlerForSuccess(false);
    when(OAuth2Util.buildScopeString(Matchers.<String[]>anyObject())).thenCallRealMethod();
    when(OAuth2Util.isOIDCAuthzRequest(Matchers.<String[]>anyObject())).thenCallRealMethod();
    IDTokenBuilder idTokenBuilder;
    if (success) {
        idTokenBuilder = getMockIDTokenBuilderForSuccess();
    } else {
        idTokenBuilder = getMockIDTokenBuilderForFailure();
    }
    when(oAuthServerConfiguration.getOpenIDConnectIDTokenBuilder()).thenReturn(idTokenBuilder);
    // Mock Issue method of the grant handler
    when(grantHandler.issue(any(OAuthTokenReqMessageContext.class))).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            OAuthTokenReqMessageContext context = invocationOnMock.getArgumentAt(0, OAuthTokenReqMessageContext.class);
            // set the scope sent in the request
            String[] scopeArray = context.getOauth2AccessTokenReqDTO().getScope();
            // Set the scope array for OIDC
            context.setScope(scopeArray);
            return new OAuth2AccessTokenRespDTO();
        }
    });
    HashMap<String, AuthorizationGrantHandler> authorizationGrantHandlers = new HashMap<>();
    authorizationGrantHandlers.put(grantType, grantHandler);
    mockOAuth2ServerConfiguration(authorizationGrantHandlers);
}
Also used : IDTokenBuilder(org.wso2.carbon.identity.openidconnect.IDTokenBuilder) OAuth2AccessTokenRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO) AuthorizationGrantHandler(org.wso2.carbon.identity.oauth2.token.handlers.grant.AuthorizationGrantHandler) HashMap(java.util.HashMap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString)

Example 3 with IDTokenBuilder

use of org.wso2.carbon.identity.openidconnect.IDTokenBuilder in project identity-inbound-auth-oauth by wso2-extensions.

the class AccessTokenIssuerTest method getMockIDTokenBuilderForFailure.

private IDTokenBuilder getMockIDTokenBuilderForFailure() throws IdentityOAuth2Exception {
    IDTokenBuilder idTokenBuilder = mock(IDTokenBuilder.class);
    when(idTokenBuilder.buildIDToken(any(OAuthTokenReqMessageContext.class), any(OAuth2AccessTokenRespDTO.class))).thenThrow(new IDTokenValidationFailureException("ID Token Validation failed"));
    return idTokenBuilder;
}
Also used : IDTokenBuilder(org.wso2.carbon.identity.openidconnect.IDTokenBuilder) OAuth2AccessTokenRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO) IDTokenValidationFailureException(org.wso2.carbon.identity.oauth2.IDTokenValidationFailureException)

Example 4 with IDTokenBuilder

use of org.wso2.carbon.identity.openidconnect.IDTokenBuilder in project identity-inbound-auth-oauth by wso2-extensions.

the class TokenResponseTypeHandler method buildIdToken.

/**
 * Handles caching user attributes and building the id_token for the OIDC implicit authz request.
 *
 * @param msgCtx
 * @param authzRespDTO
 * @throws IdentityOAuth2Exception
 */
private void buildIdToken(OAuthAuthzReqMessageContext msgCtx, OAuth2AuthorizeRespDTO authzRespDTO) throws IdentityOAuth2Exception {
    if (StringUtils.isNotBlank(authzRespDTO.getAccessToken())) {
        addUserAttributesToCache(authzRespDTO.getAccessToken(), msgCtx);
    }
    if (StringUtils.contains(msgCtx.getAuthorizationReqDTO().getResponseType(), "id_token")) {
        IDTokenBuilder builder = OAuthServerConfiguration.getInstance().getOpenIDConnectIDTokenBuilder();
        authzRespDTO.setIdToken(builder.buildIDToken(msgCtx, authzRespDTO));
    }
}
Also used : IDTokenBuilder(org.wso2.carbon.identity.openidconnect.IDTokenBuilder)

Example 5 with IDTokenBuilder

use of org.wso2.carbon.identity.openidconnect.IDTokenBuilder in project identity-inbound-auth-oauth by wso2-extensions.

the class ResponseTypeHandlerUtil method buildIdToken.

/**
 * Handles caching user attributes and building the id_token for the OIDC implicit authz request.
 *
 * @param msgCtx
 * @param authzRespDTO
 * @throws IdentityOAuth2Exception
 */
private static void buildIdToken(OAuthAuthzReqMessageContext msgCtx, OAuth2AuthorizeRespDTO authzRespDTO) throws IdentityOAuth2Exception {
    if (StringUtils.isNotBlank(authzRespDTO.getAccessToken())) {
        addUserAttributesToCache(authzRespDTO.getAccessToken(), msgCtx);
    }
    if (StringUtils.contains(msgCtx.getAuthorizationReqDTO().getResponseType(), "id_token")) {
        IDTokenBuilder builder = OAuthServerConfiguration.getInstance().getOpenIDConnectIDTokenBuilder();
        authzRespDTO.setIdToken(builder.buildIDToken(msgCtx, authzRespDTO));
    }
}
Also used : IDTokenBuilder(org.wso2.carbon.identity.openidconnect.IDTokenBuilder)

Aggregations

IDTokenBuilder (org.wso2.carbon.identity.openidconnect.IDTokenBuilder)6 OAuth2AccessTokenRespDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO)4 HashMap (java.util.HashMap)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 IDTokenValidationFailureException (org.wso2.carbon.identity.oauth2.IDTokenValidationFailureException)2 AuthorizationGrantHandler (org.wso2.carbon.identity.oauth2.token.handlers.grant.AuthorizationGrantHandler)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Matchers.anyString (org.mockito.Matchers.anyString)1 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)1 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)1 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)1 OAuthClientAuthnContext (org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext)1 JDBCPermissionBasedInternalScopeValidator (org.wso2.carbon.identity.oauth2.validators.JDBCPermissionBasedInternalScopeValidator)1 RoleBasedInternalScopeValidator (org.wso2.carbon.identity.oauth2.validators.RoleBasedInternalScopeValidator)1