当前位置: 首页>>代码示例>>Java>>正文


Java TokenResponse.getAccessToken方法代码示例

本文整理汇总了Java中org.xdi.oxauth.client.TokenResponse.getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:Java TokenResponse.getAccessToken方法的具体用法?Java TokenResponse.getAccessToken怎么用?Java TokenResponse.getAccessToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xdi.oxauth.client.TokenResponse的用法示例。


在下文中一共展示了TokenResponse.getAccessToken方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:AgarwalNeha1,项目名称:gluu,代码行数:24,代码来源:OpenIdClient.java

示例2: 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;
}
 
开发者ID:GluuFederation,项目名称:oxTrust,代码行数:16,代码来源:OpenIdClient.java

示例3: 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;
	
}
 
开发者ID:AgarwalNeha1,项目名称:gluu,代码行数:71,代码来源:Authenticator.java

示例4: 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));
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:69,代码来源:ObtainAccessTokenLoadTest.java


注:本文中的org.xdi.oxauth.client.TokenResponse.getAccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。