Search in sources :

Example 1 with JWTBearerGrant

use of com.nimbusds.oauth2.sdk.JWTBearerGrant in project product-is by wso2.

the class OAuth2ServiceJWTGrantTestCase method testAccessTokenRevokeFlow.

@Test(description = "This test case tests access token revocation flow of JWTBearerGrant.", dependsOnMethods = "testRefreshTokenFlow")
public void testAccessTokenRevokeFlow() throws Exception {
    OIDCTokens firstTokenSet = makeJWTBearerGrantRequest();
    AccessToken firstAccessToken = firstTokenSet.getAccessToken();
    makeTokenRevokeRequest(firstAccessToken);
    OIDCTokens secondTokenSet = makeJWTBearerGrantRequest();
    AccessToken secondAccessToken = secondTokenSet.getAccessToken();
    Assert.assertFalse(firstAccessToken.toJSONString().equals(secondAccessToken.toJSONString()), "Same access " + "token is returned even after the access token issued from JWT Bearer grant has been revoked. ");
}
Also used : AccessToken(com.nimbusds.oauth2.sdk.token.AccessToken) OIDCTokens(com.nimbusds.openid.connect.sdk.token.OIDCTokens) Test(org.testng.annotations.Test)

Example 2 with JWTBearerGrant

use of com.nimbusds.oauth2.sdk.JWTBearerGrant in project product-is by wso2.

the class OAuth2ServiceJWTGrantTestCase method testRefreshTokenRevokeFlow.

@Test(description = "This test case tests refresh token revocation flow of JWTBearerGrant.", dependsOnMethods = "testAccessTokenRevokeFlow")
public void testRefreshTokenRevokeFlow() throws Exception {
    OIDCTokens firstTokenSet = makeJWTBearerGrantRequest();
    RefreshToken firstRefreshToken = firstTokenSet.getRefreshToken();
    makeTokenRevokeRequest(firstRefreshToken);
    OIDCTokens secondTokenSet = makeJWTBearerGrantRequest();
    RefreshToken refreshToken = secondTokenSet.getRefreshToken();
    Assert.assertFalse(firstRefreshToken.toJSONString().equals(refreshToken.toJSONString()), "Same refresh " + "token is returned even after the refresh token issued from JWT Bearer grant has been revoked ");
}
Also used : RefreshToken(com.nimbusds.oauth2.sdk.token.RefreshToken) OIDCTokens(com.nimbusds.openid.connect.sdk.token.OIDCTokens) Test(org.testng.annotations.Test)

Example 3 with JWTBearerGrant

use of com.nimbusds.oauth2.sdk.JWTBearerGrant in project product-is by wso2.

the class OAuth2ServiceJWTGrantTestCase method testRefreshTokenFlow.

@Test(description = "This test case tests refresh token flow of JWTBearerGrant.", dependsOnMethods = "testJWTGrantTypeWithConvertOIDCDialectWithIDPMappingWithSPMappingWithAddRemainingUserAttributes")
public void testRefreshTokenFlow() throws Exception {
    AuthorizationGrant refreshGrant = new RefreshTokenGrant(new RefreshToken(refreshToken));
    OIDCTokens oidcTokens = makeTokenRequest(refreshGrant);
    Assert.assertEquals(oidcTokens.getIDToken().getJWTClaimsSet().getClaim(COUNTRY_NEW_OIDC_CLAIM), COUNTRY_CLAIM_VALUE, "User claims are not mapped correctly when AddRemainingUserAttributes and " + "ConvertToOIDCDialect is set to true in identity.xml");
    Assert.assertEquals(oidcTokens.getIDToken().getJWTClaimsSet().getClaim(EMAIL_OIDC_CLAIM), EMAIL_CLAIM_VALUE, "User claims are not mapped correctly when AddRemainingUserAttributes and " + "ConvertToOIDCDialect is set to true in identity.xml");
    Assert.assertNull(oidcTokens.getIDToken().getJWTClaimsSet().getClaim(COUNTRY_LOCAL_CLAIM_URI), "User claims conversion happened wrongly.");
    Assert.assertNull(oidcTokens.getIDToken().getJWTClaimsSet().getClaim(COUNTRY_OIDC_CLAIM), "Duplicated claims while adding missing attributes.");
}
Also used : RefreshToken(com.nimbusds.oauth2.sdk.token.RefreshToken) RefreshTokenGrant(com.nimbusds.oauth2.sdk.RefreshTokenGrant) OIDCTokens(com.nimbusds.openid.connect.sdk.token.OIDCTokens) AuthorizationGrant(com.nimbusds.oauth2.sdk.AuthorizationGrant) Test(org.testng.annotations.Test)

Example 4 with JWTBearerGrant

use of com.nimbusds.oauth2.sdk.JWTBearerGrant in project product-is by wso2.

the class OAuth2ServiceJWTGrantTestCase method makeJWTBearerGrantRequest.

/**
 * To make the JWT Bearer Grant request.
 *
 * @return OIDC Tokens.
 * @throws java.text.ParseException Parse Exception.
 * @throws URISyntaxException       URI Syntax Exception.
 * @throws IOException              IO Exception.
 * @throws ParseException           Parse Exception.
 */
private OIDCTokens makeJWTBearerGrantRequest() throws java.text.ParseException, URISyntaxException, IOException, ParseException {
    SignedJWT signedJWT = SignedJWT.parse(jwtAssertion);
    AuthorizationGrant jwtGrant = new JWTBearerGrant(signedJWT);
    return makeTokenRequest(jwtGrant);
}
Also used : JWTBearerGrant(com.nimbusds.oauth2.sdk.JWTBearerGrant) SignedJWT(com.nimbusds.jwt.SignedJWT) AuthorizationGrant(com.nimbusds.oauth2.sdk.AuthorizationGrant)

Example 5 with JWTBearerGrant

use of com.nimbusds.oauth2.sdk.JWTBearerGrant in project microsoft-authentication-library-for-java by AzureAD.

the class OnBehalfOfRequest method createAuthenticationGrant.

private static OAuthAuthorizationGrant createAuthenticationGrant(OnBehalfOfParameters parameters) {
    AuthorizationGrant jWTBearerGrant;
    try {
        jWTBearerGrant = new JWTBearerGrant(SignedJWT.parse(parameters.userAssertion().getAssertion()));
    } catch (Exception e) {
        throw new MsalClientException(e);
    }
    Map<String, List<String>> params = new HashMap<>();
    params.put("requested_token_use", Collections.singletonList("on_behalf_of"));
    if (parameters.claims() != null) {
        params.put("claims", Collections.singletonList(parameters.claims().formatAsJSONString()));
    }
    return new OAuthAuthorizationGrant(jWTBearerGrant, String.join(SCOPES_DELIMITER, parameters.scopes()), params);
}
Also used : HashMap(java.util.HashMap) JWTBearerGrant(com.nimbusds.oauth2.sdk.JWTBearerGrant) List(java.util.List) AuthorizationGrant(com.nimbusds.oauth2.sdk.AuthorizationGrant)

Aggregations

AuthorizationGrant (com.nimbusds.oauth2.sdk.AuthorizationGrant)3 OIDCTokens (com.nimbusds.openid.connect.sdk.token.OIDCTokens)3 Test (org.testng.annotations.Test)3 JWTBearerGrant (com.nimbusds.oauth2.sdk.JWTBearerGrant)2 RefreshToken (com.nimbusds.oauth2.sdk.token.RefreshToken)2 SignedJWT (com.nimbusds.jwt.SignedJWT)1 RefreshTokenGrant (com.nimbusds.oauth2.sdk.RefreshTokenGrant)1 AccessToken (com.nimbusds.oauth2.sdk.token.AccessToken)1 HashMap (java.util.HashMap)1 List (java.util.List)1