use of org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class RefreshGrantHandler method handleError.
private OAuth2AccessTokenRespDTO handleError(String errorCode, String errorMsg, OAuth2AccessTokenReqDTO tokenReqDTO) {
if (log.isDebugEnabled()) {
log.debug("OAuth-Error-Code=" + errorCode + " client-id=" + tokenReqDTO.getClientId() + " grant-type=" + tokenReqDTO.getGrantType() + " scope=" + OAuth2Util.buildScopeString(tokenReqDTO.getScope()));
}
OAuth2AccessTokenRespDTO tokenRespDTO;
tokenRespDTO = new OAuth2AccessTokenRespDTO();
tokenRespDTO.setError(true);
tokenRespDTO.setErrorCode(errorCode);
tokenRespDTO.setErrorMsg(errorMsg);
return tokenRespDTO;
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class RefreshGrantHandler method buildTokenResponse.
private OAuth2AccessTokenRespDTO buildTokenResponse(OAuthTokenReqMessageContext tokReqMsgCtx, AccessTokenDO accessTokenBean) {
String scope = OAuth2Util.buildScopeString(tokReqMsgCtx.getScope());
OAuth2AccessTokenRespDTO tokenResp = new OAuth2AccessTokenRespDTO();
tokenResp.setAccessToken(accessTokenBean.getAccessToken());
tokenResp.setTokenId(accessTokenBean.getTokenId());
tokenResp.setRefreshToken(accessTokenBean.getRefreshToken());
if (accessTokenBean.getValidityPeriodInMillis() > 0) {
tokenResp.setExpiresIn(accessTokenBean.getValidityPeriod());
tokenResp.setExpiresInMillis(accessTokenBean.getValidityPeriodInMillis());
} else {
tokenResp.setExpiresIn(Long.MAX_VALUE);
tokenResp.setExpiresInMillis(Long.MAX_VALUE);
}
tokenResp.setAuthorizedScopes(scope);
return tokenResp;
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenIssuerTest method testIssueValidateGrantError.
@Test(dataProvider = "invalidGrantErrorDataProvider")
public void testIssueValidateGrantError(boolean throwException, String exceptionMsg) throws Exception {
AuthorizationGrantHandler dummyGrantHandler = mock(AuthorizationGrantHandler.class);
when(dummyGrantHandler.isConfidentialClient()).thenReturn(false);
// Not a confidential client
when(dummyGrantHandler.isOfTypeApplicationUser()).thenReturn(true);
when(dummyGrantHandler.isAuthorizedClient(any(OAuthTokenReqMessageContext.class))).thenReturn(true);
if (throwException) {
// validate grant will throw an exception
when(dummyGrantHandler.validateGrant(any(OAuthTokenReqMessageContext.class))).thenThrow(new IdentityOAuth2Exception(exceptionMsg));
} else {
// validate grant will return false
when(dummyGrantHandler.validateGrant(any(OAuthTokenReqMessageContext.class))).thenReturn(false);
}
HashMap<String, AuthorizationGrantHandler> authorizationGrantHandlers = new HashMap<>();
authorizationGrantHandlers.put(DUMMY_GRANT_TYPE, dummyGrantHandler);
mockOAuth2ServerConfiguration(authorizationGrantHandlers);
OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO();
reqDTO.setGrantType(DUMMY_GRANT_TYPE);
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.setClientId(SOME_CLIENT_ID);
reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext);
OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO);
assertNotNull(tokenRespDTO);
assertTrue(tokenRespDTO.isError());
assertEquals(tokenRespDTO.getErrorCode(), OAuthError.TokenResponse.INVALID_GRANT);
assertEquals(tokenRespDTO.getErrorMsg(), exceptionMsg);
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenIssuerTest method testIssueWithOpenIdScopeFailure.
@Test
public void testIssueWithOpenIdScopeFailure() throws Exception {
OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO();
reqDTO.setGrantType(DUMMY_GRANT_TYPE);
reqDTO.setScope(SCOPES_WITH_OPENID);
setupOIDCScopeTest(DUMMY_GRANT_TYPE, false);
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.setClientId(SOME_CLIENT_ID);
reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext);
OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO);
assertNotNull(tokenRespDTO);
assertTrue(tokenRespDTO.isError());
assertEquals(tokenRespDTO.getErrorCode(), OAuth2ErrorCodes.SERVER_ERROR);
// ID Token should not be set
assertNull(tokenRespDTO.getIDToken());
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenIssuerTest method testIssueFailedMultipleClientAuthentication.
/**
* Multiple Client Authentication mechanisms used to authenticate the request.
*
* @throws Exception
*/
@Test
public void testIssueFailedMultipleClientAuthentication() throws Exception {
OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO();
reqDTO.setGrantType(DUMMY_GRANT_TYPE);
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.addAuthenticator("ClientAuthenticator1");
oAuthClientAuthnContext.addAuthenticator("ClientAuthenticator2");
reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext);
OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO);
assertNotNull(tokenRespDTO);
assertTrue(tokenRespDTO.isError());
assertEquals(tokenRespDTO.getErrorCode(), OAuthError.TokenResponse.INVALID_REQUEST, "Error Code has been " + "changed. Previously it was: " + OAuthError.TokenResponse.INVALID_REQUEST);
}
Aggregations