use of com.nimbusds.oauth2.sdk.token.Tokens in project product-is by wso2.
the class AdaptiveScriptTemporaryClaimPersistenceTestCase method makeTokenRequest.
/**
* Makes a token request with specified grant.
*
* @param authorizationGrant Relevant authorization grant.
* @return OIDC tokens coming from request.
* @throws Exception Exception.
*/
private OIDCTokens makeTokenRequest(AuthorizationGrant authorizationGrant, String uriString, String scopeString) throws Exception {
ClientID clientID = new ClientID(consumerKey);
Secret clientSecret = new Secret(consumerSecret);
ClientAuthentication clientAuth = new ClientSecretBasic(clientID, clientSecret);
URI uri = new URI(uriString);
Scope scope = null;
if (StringUtils.isNotBlank(scopeString)) {
scope = new Scope(scopeString);
}
TokenRequest request = new TokenRequest(uri, clientAuth, authorizationGrant, scope);
HTTPResponse tokenHTTPResp = request.toHTTPRequest().send();
Assert.assertNotNull(tokenHTTPResp, "Token http response is null.");
TokenResponse tokenResponse = OIDCTokenResponseParser.parse(tokenHTTPResp);
Assert.assertNotNull(tokenResponse, "Token response of access token response is null.");
Assert.assertFalse(tokenResponse instanceof TokenErrorResponse, "JWT access token response contains errors.");
OIDCTokenResponse oidcTokenResponse = (OIDCTokenResponse) tokenResponse;
OIDCTokens oidcTokens = oidcTokenResponse.getOIDCTokens();
Assert.assertNotNull(oidcTokens, "OIDC Tokens object is null.");
return oidcTokens;
}
use of com.nimbusds.oauth2.sdk.token.Tokens in project product-is by wso2.
the class ExtendSessionEndpointAuthCodeGrantTestCase method makeTokenRequest.
/**
* To make a token request with specified grant.
*
* @param authorizationGrant Relevant authorization grant.
* @return OIDC tokens coming from request.
* @throws Exception Exception.
*/
private OIDCTokens makeTokenRequest(AuthorizationGrant authorizationGrant, String uriString, String scopeString) throws Exception {
ClientID clientID = new ClientID(consumerKey);
Secret clientSecret = new Secret(consumerSecret);
ClientAuthentication clientAuth = new ClientSecretBasic(clientID, clientSecret);
URI uri = new URI(uriString);
Scope scope = null;
if (StringUtils.isNotBlank(scopeString)) {
scope = new Scope(scopeString);
}
TokenRequest request = new TokenRequest(uri, clientAuth, authorizationGrant, scope);
HTTPResponse tokenHTTPResp = request.toHTTPRequest().send();
Assert.assertNotNull(tokenHTTPResp, "Token http response is null.");
TokenResponse tokenResponse = OIDCTokenResponseParser.parse(tokenHTTPResp);
Assert.assertNotNull(tokenResponse, "Token response of access token response is null.");
Assert.assertFalse(tokenResponse instanceof TokenErrorResponse, "JWT access token response contains errors.");
OIDCTokenResponse oidcTokenResponse = (OIDCTokenResponse) tokenResponse;
OIDCTokens oidcTokens = oidcTokenResponse.getOIDCTokens();
Assert.assertNotNull(oidcTokens, "OIDC Tokens object is null.");
return oidcTokens;
}
use of com.nimbusds.oauth2.sdk.token.Tokens in project product-is by wso2.
the class OAuth2IDTokenEncryptionTestCase method testResourceOwnerGrantSendAuthRequestPost.
@Test(groups = "wso2.is", description = "Send authorize user request for resource owner grant type.", dependsOnMethods = "testImplicitGrantDecryptIDToken")
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 = "admin";
Secret password = new Secret("admin");
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");
}
use of com.nimbusds.oauth2.sdk.token.Tokens 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);
}
use of com.nimbusds.oauth2.sdk.token.Tokens in project Application-Gateway by gianlucafrei.
the class GitHubDriver method loadUserInfo.
@Override
protected UserModel loadUserInfo(Tokens tokens) {
AccessToken accessToken = tokens.getAccessToken();
RefreshToken refreshToken = tokens.getRefreshToken();
try {
// Load data
String email = loadUserEmail(accessToken);
GitHubUserResponse profileResponse = makeGitHubApiRequest("https://api.github.com/user", accessToken.getValue(), GitHubUserResponse.class);
// Create user model
UserModel model = new UserModel(profileResponse.id);
model.set("email", email);
model.set("picture", profileResponse.avatar_url);
model.set("preferred_username", profileResponse.login);
model.set("email_verified", "true");
model.set("sub", model.getId());
model.set("name", profileResponse.name);
model.set("profile", profileResponse.url);
model.set("updated_at", profileResponse.updated_at);
model.set("created_at", profileResponse.created_at);
model.set("access-token", accessToken.toString());
model.set("refreshToken", refreshToken != null ? refreshToken.toString() : null);
return model;
} catch (IOException | InterruptedException ex) {
throw new ApplicationException("Could not load user profile data", ex);
}
}
Aggregations