本文整理汇总了Java中org.xdi.oxauth.client.TokenResponse类的典型用法代码示例。如果您正苦于以下问题:Java TokenResponse类的具体用法?Java TokenResponse怎么用?Java TokenResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TokenResponse类属于org.xdi.oxauth.client包,在下文中一共展示了TokenResponse类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAccessToken
import org.xdi.oxauth.client.TokenResponse; //导入依赖的package包/类
private String getAccessToken(final OpenIdCredentials credential) {
// Request access token using the authorization code
logger.debug("Getting access token");
final TokenClient tokenClient = new TokenClient(this.openIdConfiguration.getTokenEndpoint());
final TokenResponse tokenResponse = tokenClient.execAuthorizationCode(credential.getAuthorizationCode(), this.appConfiguration.getOpenIdRedirectUrl(), this.clientId, this.clientSecret);
logger.trace("tokenResponse.getStatus(): '{}'", tokenResponse.getStatus());
logger.trace("tokenResponse.getErrorType(): '{}'", tokenResponse.getErrorType());
final String accessToken = tokenResponse.getAccessToken();
logger.trace("accessToken : " + accessToken);
// Validate the access token
logger.debug("Validating access token");
ValidateTokenClient validateTokenClient = new ValidateTokenClient(this.openIdConfiguration.getValidateTokenEndpoint());
final ValidateTokenResponse tokenValidationResponse = validateTokenClient.execValidateToken(accessToken);
logger.trace("tokenValidationResponse.getStatus(): '{}'", tokenValidationResponse.getStatus());
logger.trace("tokenValidationResponse.getErrorType(): '{}'", tokenValidationResponse.getErrorType());
return accessToken;
}
示例2: testObtainPatTokenUsingRefreshTokenFlow
import org.xdi.oxauth.client.TokenResponse; //导入依赖的package包/类
/**
* Test for the obtaining UMA PAT token using refresh token
*/
//@Test(dependsOnMethods = {"testObtainPatTokenFlow"})
@Parameters({"umaPatClientId", "umaPatClientSecret"})
public void testObtainPatTokenUsingRefreshTokenFlow(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
showTitle("testObtainPatTokenUsingRefreshTokenFlow");
// Request new access token using the refresh token.
TokenClient tokenClient1 = new TokenClient(tokenEndpoint);
TokenResponse response1 = tokenClient1.execRefreshToken(m_pat.getScope(), m_pat.getRefreshToken(), umaPatClientId, umaPatClientSecret);
showClient(tokenClient1);
assertEquals(response1.getStatus(), 200, "Unexpected response code: " + response1.getStatus());
assertNotNull(response1.getEntity(), "The entity is null");
assertNotNull(response1.getAccessToken(), "The access token is null");
assertNotNull(response1.getTokenType(), "The token type is null");
assertNotNull(response1.getRefreshToken(), "The refresh token is null");
assertNotNull(response1.getScope(), "The scope is null");
}
示例3: getAccessToken
import org.xdi.oxauth.client.TokenResponse; //导入依赖的package包/类
private String getAccessToken(final OpenIdCredentials credential) {
// Request access token using the authorization code
logger.debug("Getting access token");
final TokenClient tokenClient = new TokenClient(this.openIdConfiguration.getTokenEndpoint());
final TokenResponse tokenResponse = tokenClient.execAuthorizationCode(credential.getAuthorizationCode(), this.appConfiguration.getOpenIdRedirectUrl(), this.clientId, this.clientSecret);
logger.trace("tokenResponse.getStatus(): '{}'", tokenResponse.getStatus());
logger.trace("tokenResponse.getErrorType(): '{}'", tokenResponse.getErrorType());
final String accessToken = tokenResponse.getAccessToken();
logger.trace("accessToken : " + accessToken);
return accessToken;
}
示例4: exec
import org.xdi.oxauth.client.TokenResponse; //导入依赖的package包/类
public void exec() {
try {
TokenRequest request = new TokenRequest(grantType);
request.setAuthUsername(clientId);
request.setAuthPassword(clientSecret);
request.setCode(code);
request.setRedirectUri(redirectUri);
request.setUsername(username);
request.setPassword(password);
request.setScope(scope);
request.setAssertion(assertion);
request.setRefreshToken(refreshToken);
request.setAuthenticationMethod(authenticationMethod);
if (authenticationMethod.equals(AuthenticationMethod.CLIENT_SECRET_JWT)) {
request.setAudience(tokenEndpoint);
}
TokenClient client = new TokenClient(tokenEndpoint);
client.setRequest(request);
TokenResponse response = client.exec();
if (response.getStatus() == 200) {
userInfoAction.setAccessToken(response.getAccessToken());
}
showResults = true;
requestString = client.getRequestAsString();
responseString = client.getResponseAsString();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
示例5: requestAccessToken
import org.xdi.oxauth.client.TokenResponse; //导入依赖的package包/类
private String requestAccessToken(String oxAuthHost, String authorizationCode, String sessionState, String idToken, String scopes,
String clientID, String clientPassword, String tokenURL) {
TokenClient tokenClient1 = new TokenClient(tokenURL);
log.info("Sending request to token endpoint");
String redirectURL = applicationConfiguration.getLoginRedirectUrl();
log.info("redirectURI : " + applicationConfiguration.getLoginRedirectUrl());
TokenResponse tokenResponse = tokenClient1.execAuthorizationCode(authorizationCode, redirectURL, clientID, clientPassword);
log.debug(" tokenResponse : " + tokenResponse);
if (tokenResponse == null) {
log.error("Get empty token response. User rcan't log into application");
return OxTrustConstants.RESULT_NO_PERMISSIONS;
}
log.debug(" tokenResponse.getErrorType() : " + tokenResponse.getErrorType());
String accessToken = tokenResponse.getAccessToken();
log.debug(" accessToken : " + accessToken);
// 2. Validate the access token
// ValidateTokenClient validateTokenClient = new
// ValidateTokenClient(applicationConfiguration.getOxAuthValidateTokenUrl());
// ValidateTokenResponse response3 = validateTokenClient
// .execValidateToken(accessToken);
log.debug(" validating AccessToken ");
String validateUrl = applicationConfiguration.getOxAuthTokenValidationUrl();
ValidateTokenClient validateTokenClient = new ValidateTokenClient(validateUrl);
ValidateTokenResponse response3 = validateTokenClient.execValidateToken(accessToken);
log.debug(" response3.getStatus() : " + response3.getStatus());
log.debug("validate check session status:" + response3.getStatus());
if (response3.getErrorDescription() != null) {
log.debug("validate token status message:" + response3.getErrorDescription());
}
if (response3.getStatus() == 200) {
log.info("Session validation successful. User is logged in");
String userInfoEndPoint = applicationConfiguration.getOxAuthUserInfo();
UserInfoClient userInfoClient = new UserInfoClient(userInfoEndPoint);
UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);
this.oauthData.setHost(oxAuthHost);
// Determine uid
List<String> uidValues = userInfoResponse.getClaims().get(JwtClaimName.USER_NAME);
if ((uidValues == null) || (uidValues.size() == 0)) {
log.error("User info response doesn't contains uid claim");
return OxTrustConstants.RESULT_NO_PERMISSIONS;
}
this.oauthData.setUserUid(uidValues.get(0));
this.oauthData.setAccessToken(accessToken);
this.oauthData.setAccessTokenExpirationInSeconds(response3.getExpiresIn());
this.oauthData.setScopes(scopes);
this.oauthData.setIdToken(idToken);
this.oauthData.setSessionState(sessionState);
log.info("user uid:" + oauthData.getUserUid());
// Create session scope authentication service
Component.getInstance(AuthenticationSessionService.class);
return OxTrustConstants.RESULT_SUCCESS;
}
log.info("Token validation failed. User is NOT logged in");
return OxTrustConstants.RESULT_NO_PERMISSIONS;
}
示例6: obtainAccessToken
import org.xdi.oxauth.client.TokenResponse; //导入依赖的package包/类
@Parameters({"userId", "userSecret", "redirectUris"})
@Test(invocationCount = 1000, threadPoolSize = 100)
public void obtainAccessToken(final String userId, final String userSecret, String redirectUris) throws Exception {
showTitle("requestClientAssociate1");
redirectUris = "https://client.example.com/cb";
final List<ResponseType> responseTypes = new ArrayList<ResponseType>();
responseTypes.add(ResponseType.CODE);
responseTypes.add(ResponseType.ID_TOKEN);
RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
StringUtils.spaceSeparatedToList(redirectUris));
registerRequest.setResponseTypes(responseTypes);
RegisterClient registerClient = new RegisterClient(registrationEndpoint);
registerClient.setRequest(registerRequest);
RegisterResponse response = registerClient.exec();
showClient(registerClient);
assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
assertNotNull(response.getClientId());
assertNotNull(response.getClientSecret());
assertNotNull(response.getRegistrationAccessToken());
assertNotNull(response.getClientSecretExpiresAt());
final String clientId = response.getClientId();
final String clientSecret = response.getClientSecret();
// 1. Request authorization and receive the authorization code.
final List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
final AuthorizationRequest request = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUris, null);
request.setState("af0ifjsldkj");
request.setAuthUsername(userId);
request.setAuthPassword(userSecret);
request.getPrompts().add(Prompt.NONE);
final AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
authorizeClient.setRequest(request);
final AuthorizationResponse response1 = authorizeClient.exec();
ClientUtils.showClient(authorizeClient);
final String scope = response1.getScope();
final String authorizationCode = response1.getCode();
assertTrue(Util.allNotBlank(authorizationCode));
// 2. Request access token using the authorization code.
final TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE);
tokenRequest.setCode(authorizationCode);
tokenRequest.setRedirectUri(redirectUris);
tokenRequest.setAuthUsername(clientId);
tokenRequest.setAuthPassword(clientSecret);
tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);
tokenRequest.setScope(scope);
final TokenClient tokenClient1 = new TokenClient(tokenEndpoint);
tokenClient1.setRequest(tokenRequest);
final TokenResponse response2 = tokenClient1.exec();
ClientUtils.showClient(authorizeClient);
assertTrue(response2.getStatus() == 200);
final String patToken = response2.getAccessToken();
final String patRefreshToken = response2.getRefreshToken();
assertTrue(Util.allNotBlank(patToken, patRefreshToken));
}