use of com.nimbusds.oauth2.sdk.token.Tokens in project product-is by wso2.
the class OAuth2ServiceJWTGrantTestCase method makeTokenRequest.
/**
* To make a token request with specified grant.
*
* @param authorizationGrant Relevant authorization grant.
* @return OIDC tokens coming from request.
* @throws URISyntaxException URI Syntax Exception.
* @throws IOException IO Exception.
* @throws ParseException Parse Exception.
*/
private OIDCTokens makeTokenRequest(AuthorizationGrant authorizationGrant) throws URISyntaxException, IOException, ParseException {
ClientID clientID = new ClientID(consumerKey);
Secret clientSecret = new Secret(consumerSecret);
ClientAuthentication clientAuth = new ClientSecretBasic(clientID, clientSecret);
URI tokenEndpoint = new URI(OAuth2Constant.ACCESS_TOKEN_ENDPOINT);
TokenRequest request = new TokenRequest(tokenEndpoint, clientAuth, authorizationGrant, new Scope(OAuth2Constant.OAUTH2_SCOPE_OPENID + " " + OAuth2Constant.OAUTH2_SCOPE_EMAIL));
HTTPResponse tokenHTTPResp = request.toHTTPRequest().send();
Assert.assertNotNull(tokenHTTPResp, "JWT access token http response is null.");
TokenResponse tokenResponse = OIDCTokenResponseParser.parse(tokenHTTPResp);
Assert.assertNotNull(tokenResponse, "Token response of JWT access token response is null.");
Assert.assertFalse(tokenResponse instanceof TokenErrorResponse, "JWT access token response contains errors.");
OIDCTokenResponse oidcTokenResponse = (OIDCTokenResponse) tokenResponse;
JSONObject jsonObject = ((OIDCTokenResponse) tokenResponse).toJSONObject();
refreshToken = String.valueOf(jsonObject.get("refresh_token"));
OIDCTokens oidcTokens = oidcTokenResponse.getOIDCTokens();
Assert.assertNotNull(oidcTokens, "OIDC Tokens object is null in JWT token");
return oidcTokens;
}
use of com.nimbusds.oauth2.sdk.token.Tokens in project product-is by wso2.
the class OIDCSubAttributeTestCase method testAuthCodeGrantSendGetTokensPost.
@Test(groups = "wso2.is", description = "Send get access token request.", dependsOnMethods = "testAuthCodeGrantSendApprovalPost")
public void testAuthCodeGrantSendGetTokensPost() throws Exception {
ClientID clientID = new ClientID(consumerKey);
Secret clientSecret = new Secret(consumerSecret);
ClientSecretBasic clientSecretBasic = new ClientSecretBasic(clientID, clientSecret);
URI callbackURI = new URI(CALLBACK_URL);
AuthorizationCodeGrant authorizationCodeGrant = new AuthorizationCodeGrant(authorizationCode, callbackURI);
TokenRequest tokenReq = new TokenRequest(new URI(OAuth2Constant.ACCESS_TOKEN_ENDPOINT), clientSecretBasic, authorizationCodeGrant);
HTTPResponse tokenHTTPResp = tokenReq.toHTTPRequest().send();
Assert.assertNotNull(tokenHTTPResp, "Access token http response is null.");
TokenResponse tokenResponse = OIDCTokenResponseParser.parse(tokenHTTPResp);
Assert.assertNotNull(tokenResponse, "Access token response is null.");
Assert.assertFalse(tokenResponse instanceof TokenErrorResponse, "Access token response contains errors.");
OIDCTokenResponse oidcTokenResponse = (OIDCTokenResponse) tokenResponse;
OIDCTokens oidcTokens = oidcTokenResponse.getOIDCTokens();
Assert.assertNotNull(oidcTokens, "OIDC Tokens object is null.");
idToken = oidcTokens.getIDTokenString();
Assert.assertNotNull(idToken, "ID token is null");
accessToken = oidcTokens.getAccessToken().getValue();
}
use of com.nimbusds.oauth2.sdk.token.Tokens in project product-is by wso2.
the class OIDCSubAttributeTestCase method testResourceOwnerGrantSendAuthRequestPost.
@Test(groups = "wso2.is", description = "Send authorize user request for resource owner grant type.", dependsOnMethods = "testAuthCodeGrantValidateSub")
public void testResourceOwnerGrantSendAuthRequestPost() throws Exception {
// Remove previous data from variables.
sessionDataKey = null;
sessionDataKeyConsent = null;
idToken = null;
// Reset client.
client = HttpClientBuilder.create().disableRedirectHandling().build();
String username = userInfo.getUserName();
Secret password = new Secret(userInfo.getPassword());
AuthorizationGrant passwordGrant = new ResourceOwnerPasswordCredentialsGrant(username, password);
ClientID clientID = new ClientID(consumerKey);
Secret clientSecret = new Secret(consumerSecret);
ClientAuthentication clientAuth = new ClientSecretBasic(clientID, clientSecret);
Scope scope = new Scope(OAuth2Constant.OAUTH2_SCOPE_OPENID);
URI tokenEndpoint = new URI(OAuth2Constant.ACCESS_TOKEN_ENDPOINT);
TokenRequest request = new TokenRequest(tokenEndpoint, clientAuth, passwordGrant, scope);
HTTPResponse tokenHTTPResp = request.toHTTPRequest().send();
Assert.assertNotNull(tokenHTTPResp, "Access token http response is null.");
TokenResponse tokenResponse = OIDCTokenResponseParser.parse(tokenHTTPResp);
Assert.assertNotNull(tokenResponse, "Access token response is null.");
Assert.assertFalse(tokenResponse instanceof TokenErrorResponse, "Access token response contains errors.");
OIDCTokenResponse oidcTokenResponse = (OIDCTokenResponse) tokenResponse;
OIDCTokens oidcTokens = oidcTokenResponse.getOIDCTokens();
Assert.assertNotNull(oidcTokens, "OIDC Tokens object is null.");
idToken = oidcTokens.getIDTokenString();
Assert.assertNotNull(idToken, "ID token is null");
accessToken = oidcTokens.getAccessToken().getValue();
}
use of com.nimbusds.oauth2.sdk.token.Tokens in project microsoft-authentication-library-for-java by AzureAD.
the class TokenResponseTest method testConstructor.
@Test
public void testConstructor() throws ParseException {
final TokenResponse response = new TokenResponse(new BearerAccessToken("access_token"), new RefreshToken("refresh_token"), idToken, null, null, expiresIn, extExpiresIn, null, refreshIn);
Assert.assertNotNull(response);
OIDCTokens tokens = response.getOIDCTokens();
Assert.assertNotNull(tokens);
final JWT jwt = tokens.getIDToken();
Assert.assertTrue(jwt.getJWTClaimsSet().getClaims().size() >= 0);
}
use of com.nimbusds.oauth2.sdk.token.Tokens in project microsoft-authentication-library-for-java by AzureAD.
the class TokenResponseTest method testEmptyIdToken.
@Test
public void testEmptyIdToken() {
final TokenResponse response = new TokenResponse(new BearerAccessToken(idToken), new RefreshToken("refresh_token"), "", null, null, expiresIn, extExpiresIn, null, refreshIn);
Assert.assertNotNull(response);
OIDCTokens tokens = response.getOIDCTokens();
Assert.assertNotNull(tokens);
final AccessToken accessToken = tokens.getAccessToken();
Assert.assertNotNull(accessToken);
}
Aggregations