• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AccessToken类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.nimbusds.oauth2.sdk.token.AccessToken的典型用法代码示例。如果您正苦于以下问题:Java AccessToken类的具体用法?Java AccessToken怎么用?Java AccessToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AccessToken类属于com.nimbusds.oauth2.sdk.token包,在下文中一共展示了AccessToken类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: IdTokenRequest

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
public IdTokenRequest(Subject subject, OIDCClientInformation client, Scope scope, Instant authenticationTime,
		ACR acr, AMR amr, SessionID sessionId, Nonce nonce, AccessToken accessToken, AuthorizationCode code) {
	Objects.requireNonNull(subject, "subject must not be null");
	Objects.requireNonNull(client, "client must not be null");
	Objects.requireNonNull(scope, "scope must not be null");
	Objects.requireNonNull(authenticationTime, "authenticationTime must not be null");
	Objects.requireNonNull(acr, "acr must not be null");
	Objects.requireNonNull(amr, "amr must not be null");
	if (!scope.contains(OIDCScopeValue.OPENID)) {
		throw new IllegalArgumentException("Scope '" + OIDCScopeValue.OPENID + "' is required");
	}
	this.subject = subject;
	this.client = client;
	this.scope = scope;
	this.authenticationTime = authenticationTime;
	this.acr = acr;
	this.amr = amr;
	this.sessionId = sessionId;
	this.nonce = nonce;
	this.accessToken = accessToken;
	this.code = code;
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:23,代码来源:IdTokenRequest.java


示例2: grant

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Override
public Tokens grant(TokenRequest tokenRequest) throws GeneralException {
	if (!(tokenRequest.getAuthorizationGrant() instanceof RefreshTokenGrant)) {
		throw new GeneralException(OAuth2Error.UNSUPPORTED_GRANT_TYPE);
	}

	RefreshToken refreshToken = ((RefreshTokenGrant) tokenRequest.getAuthorizationGrant()).getRefreshToken();
	RefreshTokenContext context = this.refreshTokenStore.load(refreshToken);

	Subject subject = context.getSubject();
	ClientID clientId = context.getClientId();
	Scope originalScope = context.getScope();

	OIDCClientInformation client = this.clientRepository.findById(clientId);
	AccessTokenRequest accessTokenRequest = new AccessTokenRequest(subject, client, originalScope);
	AccessToken accessToken = this.tokenService.createAccessToken(accessTokenRequest);
	RefreshToken updatedRefreshToken = null;

	if (this.updateRefreshToken) {
		this.refreshTokenStore.revoke(refreshToken);
		RefreshTokenRequest refreshTokenRequest = new RefreshTokenRequest(subject, clientId, originalScope);
		updatedRefreshToken = this.tokenService.createRefreshToken(refreshTokenRequest);
	}

	return new Tokens(accessToken, updatedRefreshToken);
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:27,代码来源:RefreshTokenGrantHandler.java


示例3: grant

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Override
public Tokens grant(TokenRequest tokenRequest) throws GeneralException {
	if (!(tokenRequest.getAuthorizationGrant() instanceof ClientCredentialsGrant)) {
		throw new GeneralException(OAuth2Error.UNSUPPORTED_GRANT_TYPE);
	}

	ClientID clientId = tokenRequest.getClientAuthentication().getClientID();
	Subject subject = new Subject(clientId.getValue());

	OIDCClientInformation client = this.clientRepository.findById(clientId);
	Scope scope = this.scopeResolver.resolve(subject, tokenRequest.getScope(), client.getOIDCMetadata());
	AccessTokenRequest accessTokenRequest = new AccessTokenRequest(subject, client, scope);
	AccessToken accessToken = this.tokenService.createAccessToken(accessTokenRequest);

	return new Tokens(accessToken, null);
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:17,代码来源:ClientCredentialsGrantHandler.java


示例4: resolveAndValidateClient

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
private OIDCClientInformation resolveAndValidateClient(ClientID clientId, ProtectedResourceRequest request)
		throws GeneralException {
	OIDCClientInformation client = this.clientRepository.findById(clientId);

	if (client != null) {
		AccessToken requestAccessToken = request.getAccessToken();
		BearerAccessToken registrationAccessToken = client.getRegistrationAccessToken();
		BearerAccessToken apiAccessToken = this.apiAccessToken;

		if (requestAccessToken.equals(registrationAccessToken) || requestAccessToken.equals(apiAccessToken)) {
			return client;
		}
	}

	throw new GeneralException(BearerTokenError.INVALID_TOKEN);
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:17,代码来源:ClientRegistrationEndpoint.java


示例5: userInfoRequestInt

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Override
protected UserInfoSuccessResponse userInfoRequestInt(UserInfoRequest userReq, HttpServletResponse resp)
		throws IOException {
	// extract values from request
	AccessToken at = userReq.getAccessToken();

	// get values from honest OP for comparison
	AccessToken refAt = (AccessToken) stepCtx.get(OPContextConstants.HONEST_ACCESSTOKEN);

	// compare values
	Object fo = stepCtx.get(OPContextConstants.USERINFO_INFORMATIONLEAK_FUTURE);
	CompletableFuture<TestStepResult> f = (CompletableFuture<TestStepResult>) fo;
	if (f != null) {
		if (refAt != null && refAt.equals(at)) {
			logger.log("Detected Honest AccessToken in Evil OP.");
			f.complete(TestStepResult.FAIL);
		} else if (at != null) {
			logger.log("Detected unknown AccessToken in Evil OP.");
			f.complete(TestStepResult.FAIL);
		}
	}

	return super.userInfoRequestInt(userReq, resp);
}
 
开发者ID:RUB-NDS,项目名称:PrOfESSOS,代码行数:25,代码来源:MaliciousEndpointOP.java


示例6: userInfoRequestInt

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Nullable
protected UserInfoSuccessResponse userInfoRequestInt(UserInfoRequest userReq, HttpServletResponse resp)
		throws IOException {
	AccessToken at = userReq.getAccessToken();
	if (at == null) {
		UserInfoErrorResponse errorResp = new UserInfoErrorResponse(BearerTokenError.MISSING_TOKEN);
		sendErrorResponse("User Info", errorResp, resp);
		return null;
	}
	//AccessTokenHash atHash = AccessTokenHash.compute(at, JWSAlgorithm.RS256);

	UserInfo ui = getUserInfo();

	UserInfoSuccessResponse uiResp = new UserInfoSuccessResponse(ui);
	return uiResp;
}
 
开发者ID:RUB-NDS,项目名称:PrOfESSOS,代码行数:17,代码来源:DefaultOP.java


示例7: complete

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
protected AuthenticationMechanismOutcome complete(JWTClaimsSet claims, AccessToken accessToken, String returnURL, HttpServerExchange exchange, boolean redirect) throws Exception {
	OIDCPrincipal principal = new OIDCPrincipalExt(claims, accessToken);
	Account account = new AccountImpl(principal);
	account = identityManager.verify(account);
	if (account == null) {
		LOG.warning(String.format("OIDC subject %s not found in identity manager", principal.getName()));
		exchange.getSecurityContext().authenticationFailed("OIDC subject not found in identity manager", mechanismName);
		OIDCContext oidcContext = exchange.getAttachment(OIDCContext.ATTACHMENT_KEY);
		oidcContext.setError(true);
		return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
	}
	exchange.getSecurityContext().authenticationComplete(account, mechanismName, true);
	if (redirect) {
		exchange.getResponseHeaders().put(Headers.LOCATION, returnURL != null && !returnURL.isEmpty() ? returnURL : "/");
		exchange.setStatusCode(HttpServletResponse.SC_FOUND);
		exchange.endExchange();
	}
	LOG.fine("authentificated " + principal);
	return AuthenticationMechanismOutcome.AUTHENTICATED;
}
 
开发者ID:aaronanderson,项目名称:swarm-oidc,代码行数:21,代码来源:OIDCAuthenticationMechanism.java


示例8: getMockAccessToken

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
/**
 * TODO
 * To create a mock access token. We do not use it for anything yet. 
 * 
 * @return mock access token.
 */
private AccessToken getMockAccessToken() {
    if (getAuthenticationRequest().getResponseType().contains(ResponseType.Value.TOKEN)){
        return new BearerAccessToken();
    }
    return null;
}
 
开发者ID:CSCfi,项目名称:shibboleth-idp-oidc-extension,代码行数:13,代码来源:FormOutboundAuthenticationResponseMessage.java


示例9: grant

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Override
public Tokens grant(TokenRequest tokenRequest) throws GeneralException {
	if (!(tokenRequest.getAuthorizationGrant() instanceof ResourceOwnerPasswordCredentialsGrant)) {
		throw new GeneralException(OAuth2Error.UNSUPPORTED_GRANT_TYPE);
	}

	Scope requestedScope = tokenRequest.getScope();
	if (!requestedScope.contains(OIDCScopeValue.OPENID)) {
		throw new GeneralException(
				OAuth2Error.INVALID_SCOPE.setDescription("The scope must include an \"openid\" value"));
	}

	Subject subject = this.passwordAuthenticationHandler
			.authenticate((ResourceOwnerPasswordCredentialsGrant) tokenRequest.getAuthorizationGrant());
	ClientID clientId = tokenRequest.getClientAuthentication().getClientID();

	OIDCClientInformation client = this.clientRepository.findById(clientId);
	Scope scope = this.scopeResolver.resolve(subject, requestedScope, client.getOIDCMetadata());
	AccessTokenRequest accessTokenRequest = new AccessTokenRequest(subject, client, scope);
	AccessToken accessToken = this.tokenService.createAccessToken(accessTokenRequest);
	RefreshToken refreshToken = null;

	if (client.getOIDCMetadata().getGrantTypes().contains(GrantType.REFRESH_TOKEN)) {
		RefreshTokenRequest refreshTokenRequest = new RefreshTokenRequest(subject, clientId, scope);
		refreshToken = this.tokenService.createRefreshToken(refreshTokenRequest);
	}

	return new Tokens(accessToken, refreshToken);
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:30,代码来源:ResourceOwnerPasswordCredentialsGrantHandler.java


示例10: validateAccessToken

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
private void validateAccessToken(AccessToken requestAccessToken) throws GeneralException {
	BearerAccessToken apiAccessToken = this.apiAccessToken;

	if (requestAccessToken == null || !requestAccessToken.equals(apiAccessToken)) {
		throw new GeneralException(BearerTokenError.INVALID_TOKEN);
	}
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:8,代码来源:ClientRegistrationEndpoint.java


示例11: handleImplicitFlow

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
private AuthenticationSuccessResponse handleImplicitFlow(AuthenticationRequest authRequest,
		OIDCClientInformation client, HttpServletRequest request, Subject subject) throws GeneralException {
	ResponseType responseType = authRequest.getResponseType();
	ResponseMode responseMode = authRequest.impliedResponseMode();
	URI redirectUri = authRequest.getRedirectionURI();
	Scope requestedScope = authRequest.getScope();
	State state = authRequest.getState();
	Nonce nonce = authRequest.getNonce();

	Instant authenticationTime = Instant.ofEpochMilli(request.getSession().getCreationTime());
	ACR acr = this.acr;
	AMR amr = AMR.PWD;
	SessionID sessionId = new SessionID(request.getSession().getId());
	State sessionState = this.sessionManagementEnabled ? State.parse(sessionId.getValue()) : null;

	Scope scope = this.scopeResolver.resolve(subject, requestedScope, client.getOIDCMetadata());
	AccessToken accessToken = null;

	if (responseType.contains(ResponseType.Value.TOKEN)) {
		AccessTokenRequest accessTokenRequest = new AccessTokenRequest(subject, client, scope);
		accessToken = this.tokenService.createAccessToken(accessTokenRequest);
	}

	IdTokenRequest idTokenRequest = new IdTokenRequest(subject, client, scope, authenticationTime, acr, amr,
			sessionId, nonce, accessToken, null);
	JWT idToken = this.tokenService.createIdToken(idTokenRequest);

	return new AuthenticationSuccessResponse(redirectUri, null, idToken, accessToken, state, sessionState,
			responseMode);
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:31,代码来源:AuthorizationEndpoint.java


示例12: handleHybridFlow

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
private AuthenticationSuccessResponse handleHybridFlow(AuthenticationRequest authRequest,
		OIDCClientInformation client, HttpServletRequest request, Subject subject) throws GeneralException {
	ResponseType responseType = authRequest.getResponseType();
	ResponseMode responseMode = authRequest.impliedResponseMode();
	ClientID clientId = authRequest.getClientID();
	URI redirectUri = authRequest.getRedirectionURI();
	Scope requestedScope = authRequest.getScope();
	State state = authRequest.getState();
	CodeChallenge codeChallenge = authRequest.getCodeChallenge();
	CodeChallengeMethod codeChallengeMethod = authRequest.getCodeChallengeMethod();
	Nonce nonce = authRequest.getNonce();

	Instant authenticationTime = Instant.ofEpochMilli(request.getSession().getCreationTime());
	ACR acr = this.acr;
	AMR amr = AMR.PWD;
	SessionID sessionId = new SessionID(request.getSession().getId());
	State sessionState = this.sessionManagementEnabled ? State.parse(sessionId.getValue()) : null;

	Scope scope = this.scopeResolver.resolve(subject, requestedScope, client.getOIDCMetadata());
	AuthorizationCodeContext context = new AuthorizationCodeContext(subject, clientId, redirectUri, scope,
			authenticationTime, acr, amr, sessionId, codeChallenge, codeChallengeMethod, nonce);
	AuthorizationCode code = this.authorizationCodeService.create(context);
	AccessToken accessToken = null;

	if (responseType.contains(ResponseType.Value.TOKEN)) {
		AccessTokenRequest accessTokenRequest = new AccessTokenRequest(subject, client, scope);
		accessToken = this.tokenService.createAccessToken(accessTokenRequest);
	}

	JWT idToken = null;

	if (responseType.contains(OIDCResponseTypeValue.ID_TOKEN)) {
		IdTokenRequest idTokenRequest = new IdTokenRequest(subject, client, scope, authenticationTime, acr, amr,
				sessionId, nonce, accessToken, code);
		idToken = this.tokenService.createIdToken(idTokenRequest);
	}

	return new AuthenticationSuccessResponse(redirectUri, code, idToken, accessToken, state, sessionState,
			responseMode);
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:41,代码来源:AuthorizationEndpoint.java


示例13: tokenRequestInt

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Nullable
protected OIDCTokenResponse tokenRequestInt(TokenRequest tokenReq, HttpServletResponse resp)
		throws GeneralSecurityException, JOSEException, ParseException {
	ClientAuthentication auth = tokenReq.getClientAuthentication();
	ClientID clientId = auth != null ? auth.getClientID() : tokenReq.getClientID();
	AuthorizationGrant grant = tokenReq.getAuthorizationGrant();
	CodeHash cHash = null;
	if (grant != null && grant.getType() == GrantType.AUTHORIZATION_CODE) {
		AuthorizationCodeGrant codeGrant = (AuthorizationCodeGrant) grant;
		cHash = CodeHash.compute(codeGrant.getAuthorizationCode(), JWSAlgorithm.RS256);
	}

	AccessToken at = new BearerAccessToken();
	AccessTokenHash atHash = AccessTokenHash.compute(at, JWSAlgorithm.RS256);
	// save access token if honest op
	if (type == OPType.HONEST) {
		stepCtx.put(OPContextConstants.HONEST_ACCESSTOKEN, at);
	}

	Nonce nonce = (Nonce) stepCtx.get(OPContextConstants.AUTH_REQ_NONCE);

	JWT idToken = getIdToken(clientId, nonce, atHash, cHash);

	OIDCTokens tokens = new OIDCTokens(idToken, at, null);
	OIDCTokenResponse tokenRes = new OIDCTokenResponse(tokens);

	return tokenRes;
}
 
开发者ID:RUB-NDS,项目名称:PrOfESSOS,代码行数:29,代码来源:DefaultOP.java


示例14: processOIDCAuthResponse

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
protected AuthenticationMechanismOutcome processOIDCAuthResponse(HttpServerExchange exchange) {
	try {
		AuthenticationResponse authResp = authenticate(exchange);

		if (authResp instanceof AuthenticationErrorResponse) {
			ErrorObject error = ((AuthenticationErrorResponse) authResp).getErrorObject();
			throw new IllegalStateException(String.format("OIDC Authentication error: code %s description: %s", error.getCode(), error.getDescription()));
		}

		AuthenticationSuccessResponse successResponse = (AuthenticationSuccessResponse) authResp;

		// could store returnURL/state
		// in session but state is encrypted
		State state = successResponse.getState();
		String returnURL = restoreState(state != null ? state.getValue() : null, exchange);

		AuthorizationCode authCode = successResponse.getAuthorizationCode();
		JWT idToken = successResponse.getIDToken();
		AccessToken accessToken = successResponse.getAccessToken();

		if (idToken == null && authCode != null) {
			OIDCTokenResponse tokenResponse = fetchToken(authCode, exchange);
			idToken = tokenResponse.getOIDCTokens().getIDToken();
			accessToken = tokenResponse.getOIDCTokens().getAccessToken();
		}
		validateToken(idToken, exchange, true);
		return complete(idToken.getJWTClaimsSet(), accessToken, returnURL, exchange, true);

	} catch (Exception e) {
		LOG.log(Level.SEVERE, "", e);
		OIDCContext oidcContext = exchange.getAttachment(OIDCContext.ATTACHMENT_KEY);
		oidcContext.setError(true);
		exchange.getSecurityContext().authenticationFailed("OIDC auth response processing failed", mechanismName);
		return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
	}

}
 
开发者ID:aaronanderson,项目名称:swarm-oidc,代码行数:38,代码来源:OIDCAuthenticationMechanism.java


示例15: handle

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Override
public Response handle(HTTPRequest httpRequest, OIDCResourceReference reference) throws Exception
{
    // Parse the request
    UserInfoRequest request = UserInfoRequest.parse(httpRequest);

    // Get the token associated to the user
    AccessToken accessToken = request.getAccessToken();

    // UserInfoSuccessResponse
    return null;
}
 
开发者ID:xwiki-contrib,项目名称:oidc,代码行数:13,代码来源:JWKOIDCEndpoint.java


示例16: getConsent

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
public OIDCConsent getConsent(AccessToken accessToken) throws QueryException, XWikiException
{
    Map<String, String> entries = new HashMap<>();

    entries.put(OIDCConsent.FIELD_ACCESSTOKEN, accessToken.getValue());

    return getConsent(entries);
}
 
开发者ID:xwiki-contrib,项目名称:oidc,代码行数:9,代码来源:OIDCStore.java


示例17: setAccessToken

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
public void setAccessToken(AccessToken accessToken)
{
    if (accessToken == null) {
        removeField(FIELD_ACCESSTOKEN);
    } else {
        setStringValue(FIELD_ACCESSTOKEN, accessToken.getValue());
    }
}
 
开发者ID:xwiki-contrib,项目名称:oidc,代码行数:9,代码来源:OIDCConsent.java


示例18: login

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
/**
 * Single entry point for all login functionalities.
 * 
 * @param type login type (maps to a specific configuration file)
 * @param request
 * @param response
 * @param session
 * @throws OSDIConfigurationException
 */
@RequestMapping(value = "/login/{type}", method = RequestMethod.GET)
public void login(@PathVariable String type, HttpServletRequest request, HttpServletResponse response,
		HttpSession session) throws OSDIConfigurationException {
	// get configuration for the requested type
	OSDIConfigurationKVP configuration = (OSDIConfigurationKVP)loadConfiguration(request); 
	if(request.getParameter("code") == null || request.getParameter("code").trim().isEmpty()) {
		// 1st step: called by the app login page
		oAuthService.login(configuration, request, response, session);
	} else {
		// 2nd step: OAuth 2.0 service callback
		String state = request.getParameter("state");
		// check 
		if (session.getAttribute("state") == null || !state.equals(request.getSession().getAttribute("state"))) {
            throw new IllegalArgumentException("Login failed");
		} else {
			// retrieve access token
			AccessToken token = oAuthService.getToken(configuration, request.getParameter("code"));
			if(token != null) {
				// redirect back to the client
				oAuthService.returnToClient(configuration, response, session, token);
			} else {
				throw new IllegalArgumentException("Login failed");
			}
		}
	}
	
}
 
开发者ID:geosolutions-it,项目名称:OpenSDI-Manager2,代码行数:37,代码来源:OAuth2Controller.java


示例19: returnToClient

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Override
public void returnToClient(OSDIConfigurationKVP configuration, HttpServletResponse response, HttpSession session, AccessToken token) {
	try {
		response.sendRedirect((String)session.getAttribute("returnPage") + "?token=" + token.toJSONString());
	} catch (IOException e) {
		throw new IllegalArgumentException("Error calling application page");
	}
	
}
 
开发者ID:geosolutions-it,项目名称:OpenSDI-Manager2,代码行数:10,代码来源:OpenIdConnectLoginService.java


示例20: createAccessToken

import com.nimbusds.oauth2.sdk.token.AccessToken; //导入依赖的package包/类
@Override
public AccessToken createAccessToken(AccessTokenRequest accessTokenRequest) {
	Instant now = Instant.now();

	Subject subject = accessTokenRequest.getSubject();
	OIDCClientInformation client = accessTokenRequest.getClient();
	Scope scope = accessTokenRequest.getScope();

	Set<Audience> audiences = new LinkedHashSet<>();
	audiences.add(new Audience(this.issuer));

	for (Scope.Value value : scope) {
		String resource = this.resourceScopes.get(value);

		if (resource != null) {
			audiences.add(new Audience(resource));
		}
	}

	Date expirationTime = Date.from(now.plus(this.accessTokenLifetime));
	Date issueTime = Date.from(now);
	JWTID jwtId = new JWTID(UUID.randomUUID().toString());
	UserInfo userInfo = this.claimSource.load(subject, new HashSet<>(this.accessTokenSubjectClaims));
	userInfo.setClaim(this.accessTokenScopeClaim, scope);
	userInfo.setClaim(this.accessTokenClientIdClaim, client.getID());

	try {
		JWTAssertionDetails details = new JWTAssertionDetails(this.issuer, userInfo.getSubject(),
				new ArrayList<>(audiences), expirationTime, issueTime, issueTime, jwtId, userInfo.toJSONObject());
		SignedJWT accessToken;

		if (JWSAlgorithm.Family.HMAC_SHA.contains(this.accessTokenJwsAlgorithm)) {
			Secret secret = client.getSecret();

			accessToken = JWTAssertionFactory.create(details, this.accessTokenJwsAlgorithm, secret);
		}
		else if (JWSAlgorithm.Family.RSA.contains(this.accessTokenJwsAlgorithm)) {
			RSAKey rsaKey = (RSAKey) resolveJwk(this.accessTokenJwsAlgorithm);

			accessToken = JWTAssertionFactory.create(details, this.accessTokenJwsAlgorithm,
					rsaKey.toRSAPrivateKey(), rsaKey.getKeyID(), jcaProvider);
		}
		else if (JWSAlgorithm.Family.EC.contains(this.accessTokenJwsAlgorithm)) {
			ECKey ecKey = (ECKey) resolveJwk(this.accessTokenJwsAlgorithm);

			accessToken = JWTAssertionFactory.create(details, this.accessTokenJwsAlgorithm, ecKey.toECPrivateKey(),
					ecKey.getKeyID(), jcaProvider);
		}
		else {
			throw new KeyException("Unsupported algorithm: " + this.accessTokenJwsAlgorithm);
		}

		return new BearerAccessToken(accessToken.serialize(), this.accessTokenLifetime.getSeconds(), scope);
	}
	catch (JOSEException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:59,代码来源:DefaultTokenService.java



注:本文中的com.nimbusds.oauth2.sdk.token.AccessToken类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Text类代码示例发布时间:2022-05-23
下一篇:
Java ListPopupStep类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap