本文整理汇总了Java中com.nimbusds.oauth2.sdk.TokenResponse类的典型用法代码示例。如果您正苦于以下问题:Java TokenResponse类的具体用法?Java TokenResponse怎么用?Java TokenResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenResponse类属于com.nimbusds.oauth2.sdk包,在下文中一共展示了TokenResponse类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: exchange
import com.nimbusds.oauth2.sdk.TokenResponse; //导入依赖的package包/类
@Override
public TokenResponseAttributes exchange(
AuthorizationCodeAuthenticationToken authorizationCodeAuthenticationToken)
throws OAuth2AuthenticationException {
ClientRegistration clientRegistration = authorizationCodeAuthenticationToken.getClientRegistration();
AuthorizationCode authorizationCode = new AuthorizationCode(
authorizationCodeAuthenticationToken.getAuthorizationCode());
AuthorizationGrant authorizationCodeGrant = new AuthorizationCodeGrant(
authorizationCode, URI.create(clientRegistration.getRedirectUri()));
URI tokenUri = URI.create(clientRegistration.getProviderDetails().getTokenUri());
ClientID clientId = new ClientID(clientRegistration.getClientId());
Secret clientSecret = new Secret(clientRegistration.getClientSecret());
ClientAuthentication clientAuthentication = new ClientSecretGet(clientId, clientSecret);
try {
HTTPRequest httpRequest = createTokenRequest(
clientRegistration, authorizationCodeGrant,
tokenUri, clientAuthentication);
TokenResponse tokenResponse = TokenResponse.parse(httpRequest.send());
if (!tokenResponse.indicatesSuccess()) {
OAuth2Error errorObject = new OAuth2Error("invalid_token_response");
throw new OAuth2AuthenticationException(errorObject, "error");
}
return createTokenResponse((AccessTokenResponse) tokenResponse);
} catch (MalformedURLException e) {
throw new SerializeException(e.getMessage(), e);
} catch (ParseException pe) {
throw new OAuth2AuthenticationException(new OAuth2Error("invalid_token_response"), pe);
} catch (IOException ioe) {
throw new AuthenticationServiceException(
"An error occurred while sending the Access Token Request: " +
ioe.getMessage(), ioe);
}
}
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:43,代码来源:FacebookAuthorizationGrantTokenExchanger.java
示例2: fetchToken
import com.nimbusds.oauth2.sdk.TokenResponse; //导入依赖的package包/类
protected OIDCTokenResponse fetchToken(AuthorizationCode authCode, HttpServerExchange exchange) throws Exception {
URI redirectURI = new URI(RedirectBuilder.redirect(exchange, redirectPath));
TokenRequest tokenReq = new TokenRequest(oidcProvider.getTokenURI(), oidcProvider.getClientId(), new AuthorizationCodeGrant(authCode, redirectURI));
HTTPResponse tokenHTTPResp = tokenReq.toHTTPRequest().send();
TokenResponse tokenResponse = OIDCTokenResponseParser.parse(tokenHTTPResp);
if (tokenResponse instanceof TokenErrorResponse) {
ErrorObject error = ((TokenErrorResponse) tokenResponse).getErrorObject();
throw new IllegalStateException(String.format("OIDC TokenRequest error: code %s description: %s", error.getCode(), error.getDescription()));
}
return (OIDCTokenResponse) tokenResponse;
}
开发者ID:aaronanderson,项目名称:swarm-oidc,代码行数:12,代码来源:OIDCAuthenticationMechanism.java
注:本文中的com.nimbusds.oauth2.sdk.TokenResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论