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;
}
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);
}
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;
}
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));
}
}
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));
}
}
Aggregations