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

Java BearerAccessToken类代码示例

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

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



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

示例1: create

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Override
public OIDCClientInformation create(OIDCClientMetadata metadata, boolean dynamicRegistration) {
	metadata.applyDefaults();
	ClientID id = new ClientID(UUID.randomUUID().toString());
	Instant issueDate = Instant.now();
	Secret secret = isTokenEndpointAuthEnabled(metadata) ? new Secret() : null;
	URI registrationUri = dynamicRegistration
			? URI.create(this.registrationUriTemplate.replace("{id}", id.getValue()))
			: null;
	BearerAccessToken accessToken = dynamicRegistration ? new BearerAccessToken() : null;

	OIDCClientInformation client = new OIDCClientInformation(id, Date.from(issueDate), metadata, secret,
			registrationUri, accessToken);
	this.clientRepository.save(client);

	return client;
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:18,代码来源:DefaultClientService.java


示例2: mapRow

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Override
public OIDCClientInformation mapRow(ResultSet rs, int rowNum) throws SQLException {
	try {
		String id = rs.getString("id");
		Date issueDate = rs.getTimestamp("issue_date");
		String metadata = rs.getString("metadata");
		String secret = rs.getString("secret");
		String registrationUri = rs.getString("registration_uri");
		String accessToken = rs.getString("access_token");

		return new OIDCClientInformation(new ClientID(id), issueDate,
				OIDCClientMetadata.parse(JSONObjectUtils.parse(metadata)),
				(secret != null) ? new Secret(secret) : null,
				(registrationUri != null) ? URI.create(registrationUri) : null,
				(accessToken != null) ? new BearerAccessToken(accessToken) : null);
	}
	catch (ParseException e) {
		throw new TypeMismatchDataAccessException(e.getMessage(), e);
	}
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:21,代码来源:JdbcClientRepository.java


示例3: getClientRegistrations

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@GetMapping
public void getClientRegistrations(HttpServletRequest request, HttpServletResponse response) throws Exception {
	HTTPRequest httpRequest = ServletUtils.createHTTPRequest(request);

	try {
		String authorizationHeader = httpRequest.getAuthorization();

		if (authorizationHeader == null) {
			throw new GeneralException(BearerTokenError.INVALID_TOKEN);
		}

		BearerAccessToken requestAccessToken = BearerAccessToken.parse(authorizationHeader);
		validateAccessToken(requestAccessToken);
		List<OIDCClientInformation> clients = this.clientRepository.findAll();

		response.setContentType("application/json; charset=UTF-8");

		PrintWriter writer = response.getWriter();
		writer.print(toJsonObject(clients).toJSONString());
		writer.close();
	}
	catch (GeneralException e) {
		ClientRegistrationResponse registrationResponse = new ClientRegistrationErrorResponse(e.getErrorObject());
		ServletUtils.applyHTTPResponse(registrationResponse.toHTTPResponse(), response);
	}
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:27,代码来源:ClientRegistrationEndpoint.java


示例4: resolveAndValidateClient

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的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: implicitWithIdTokenAndToken_minimumParams_isSuccess

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void implicitWithIdTokenAndToken_minimumParams_isSuccess() throws Exception {
	BearerAccessToken accessToken = new BearerAccessToken();
	JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());

	given(this.clientRepository.findById(any(ClientID.class))).willReturn(implicitWithIdTokenAndTokenClient());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
	given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.will(returnsSecondArg());

	MockHttpServletRequestBuilder request = get(
			"/oauth2/authorize?scope=openid&response_type=id_token token&client_id=test-client&redirect_uri=http://example.com&nonce=test")
					.session(this.session);
	this.mvc.perform(request).andExpect(status().isFound())
			.andExpect(redirectedUrlTemplate(
					"http://example.com#access_token={accessToken}&id_token={idToken}&token_type=Bearer",
					accessToken.getValue(), idToken.serialize()));
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:21,代码来源:AuthorizationEndpointTests.java


示例6: implicitWithIdTokenAndToken_withState_isSuccess

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void implicitWithIdTokenAndToken_withState_isSuccess() throws Exception {
	BearerAccessToken accessToken = new BearerAccessToken();
	JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
	State state = new State();

	given(this.clientRepository.findById(any(ClientID.class))).willReturn(implicitWithIdTokenAndTokenClient());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
	given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.will(returnsSecondArg());

	MockHttpServletRequestBuilder request = get(
			"/oauth2/authorize?scope=openid&response_type=id_token token&client_id=test-client&redirect_uri=http://example.com&nonce=test&state="
					+ state.getValue()).session(this.session);
	this.mvc.perform(request).andExpect(status().isFound()).andExpect(redirectedUrlTemplate(
			"http://example.com#access_token={accessToken}&id_token={idToken}&state={state}&token_type=Bearer",
			accessToken.getValue(), idToken.serialize(), state.getValue()));
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:21,代码来源:AuthorizationEndpointTests.java


示例7: hybridWithIdTokenAndToken_minimumParams_isSuccess

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void hybridWithIdTokenAndToken_minimumParams_isSuccess() throws Exception {
	BearerAccessToken accessToken = new BearerAccessToken();
	JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
	AuthorizationCode authorizationCode = new AuthorizationCode();

	given(this.clientRepository.findById(any(ClientID.class))).willReturn(hybridWithIdTokenAndTokenClient());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
	given(this.authorizationCodeService.create(any(AuthorizationCodeContext.class))).willReturn(authorizationCode);
	given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.will(returnsSecondArg());

	MockHttpServletRequestBuilder request = get(
			"/oauth2/authorize?scope=openid&response_type=code id_token token&client_id=test-client&redirect_uri=http://example.com&nonce=test")
					.session(this.session);
	this.mvc.perform(request).andExpect(status().isFound()).andExpect(redirectedUrlTemplate(
			"http://example.com#access_token={accessToken}&code={code}&id_token={idToken}&token_type=Bearer",
			accessToken.getValue(), authorizationCode.getValue(), idToken.serialize()));
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:22,代码来源:AuthorizationEndpointTests.java


示例8: hybridWithToken_minimumParams_isSuccess

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void hybridWithToken_minimumParams_isSuccess() throws Exception {
	BearerAccessToken accessToken = new BearerAccessToken();
	AuthorizationCode authorizationCode = new AuthorizationCode();

	given(this.clientRepository.findById(any(ClientID.class))).willReturn(hybridWithTokenClient());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.authorizationCodeService.create(any(AuthorizationCodeContext.class))).willReturn(authorizationCode);
	given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.will(returnsSecondArg());

	MockHttpServletRequestBuilder request = get(
			"/oauth2/authorize?scope=openid&response_type=code token&client_id=test-client&redirect_uri=http://example.com&nonce=test")
					.session(this.session);
	this.mvc.perform(request).andExpect(status().isFound())
			.andExpect(redirectedUrlTemplate(
					"http://example.com#access_token={accessToken}&code={code}&token_type=Bearer",
					accessToken.getValue(), authorizationCode.getValue()));
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:21,代码来源:AuthorizationEndpointTests.java


示例9: hybridWithIdTokenAndToken_withState_isSuccess

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void hybridWithIdTokenAndToken_withState_isSuccess() throws Exception {
	BearerAccessToken accessToken = new BearerAccessToken();
	JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
	AuthorizationCode authorizationCode = new AuthorizationCode();
	State state = new State();

	given(this.clientRepository.findById(any(ClientID.class))).willReturn(hybridWithIdTokenAndTokenClient());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
	given(this.authorizationCodeService.create(any(AuthorizationCodeContext.class))).willReturn(authorizationCode);
	given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.will(returnsSecondArg());

	MockHttpServletRequestBuilder request = get(
			"/oauth2/authorize?scope=openid&response_type=code id_token token&client_id=test-client&redirect_uri=http://example.com&nonce=test&state="
					+ state.getValue()).session(this.session);
	this.mvc.perform(request).andExpect(status().isFound()).andExpect(redirectedUrlTemplate(
			"http://example.com#access_token={accessToken}&code={code}&id_token={idToken}&state={state}&token_type=Bearer",
			accessToken.getValue(), authorizationCode.getValue(), idToken.serialize(), state.getValue()));
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:23,代码来源:AuthorizationEndpointTests.java


示例10: authCode_postAuth_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void authCode_postAuth_isOk() throws Exception {
	ClientID clientId = new ClientID("test-client");
	URI redirectUri = URI.create("http://rp.example.com");
	AuthorizationCode authorizationCode = new AuthorizationCode();

	ClientSecretPost clientAuth = new ClientSecretPost(clientId, new Secret("test-secret"));
	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
			new AuthorizationCodeGrant(authorizationCode, redirectUri));

	AuthorizationCodeContext context = new AuthorizationCodeContext(new Subject("user"), clientId, redirectUri,
			new Scope(OIDCScopeValue.OPENID), Instant.now(), new ACR("1"), AMR.PWD, new SessionID("test"), null,
			null, null);
	BearerAccessToken accessToken = new BearerAccessToken();
	JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());

	given(this.clientRepository.findById(any(ClientID.class)))
			.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_POST));
	given(this.authorizationCodeService.consume(eq(authorizationCode))).willReturn(context);
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED);
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:27,代码来源:TokenEndpointTests.java


示例11: authCode_pkcePlain_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void authCode_pkcePlain_isOk() throws Exception {
	ClientID clientId = new ClientID("test-client");
	URI redirectUri = URI.create("http://rp.example.com");
	CodeVerifier codeVerifier = new CodeVerifier();
	CodeChallengeMethod codeChallengeMethod = CodeChallengeMethod.PLAIN;
	AuthorizationCode authorizationCode = new AuthorizationCode();

	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientId,
			new AuthorizationCodeGrant(authorizationCode, redirectUri, codeVerifier));

	AuthorizationCodeContext context = new AuthorizationCodeContext(new Subject("user"), clientId, redirectUri,
			new Scope(OIDCScopeValue.OPENID), Instant.now(), new ACR("1"), AMR.PWD, new SessionID("test"),
			CodeChallenge.compute(codeChallengeMethod, codeVerifier), codeChallengeMethod, null);
	BearerAccessToken accessToken = new BearerAccessToken();
	JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());

	given(this.clientRepository.findById(any(ClientID.class))).willReturn(client(ClientAuthenticationMethod.NONE));
	given(this.authorizationCodeService.consume(eq(authorizationCode))).willReturn(context);
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED);
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:27,代码来源:TokenEndpointTests.java


示例12: authCode_pkceS256_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void authCode_pkceS256_isOk() throws Exception {
	ClientID clientId = new ClientID("test-client");
	URI redirectUri = URI.create("http://rp.example.com");
	CodeVerifier codeVerifier = new CodeVerifier();
	CodeChallengeMethod codeChallengeMethod = CodeChallengeMethod.S256;
	AuthorizationCode authorizationCode = new AuthorizationCode();

	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientId,
			new AuthorizationCodeGrant(authorizationCode, URI.create("http://rp.example.com"), codeVerifier));

	AuthorizationCodeContext context = new AuthorizationCodeContext(new Subject("user"), clientId, redirectUri,
			new Scope(OIDCScopeValue.OPENID), Instant.now(), new ACR("1"), AMR.PWD, new SessionID("test"),
			CodeChallenge.compute(codeChallengeMethod, codeVerifier), codeChallengeMethod, null);
	BearerAccessToken accessToken = new BearerAccessToken();
	JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());

	given(this.clientRepository.findById(any(ClientID.class))).willReturn(client(ClientAuthenticationMethod.NONE));
	given(this.authorizationCodeService.consume(eq(authorizationCode))).willReturn(context);
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED);
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:27,代码来源:TokenEndpointTests.java


示例13: resourceOwnerPasswordCredentials_basicAuth_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void resourceOwnerPasswordCredentials_basicAuth_isOk() throws Exception {
	ClientSecretBasic clientAuth = new ClientSecretBasic(new ClientID("test-client"), new Secret("test-secret"));
	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
			new ResourceOwnerPasswordCredentialsGrant("user", new Secret("password")),
			new Scope(OIDCScopeValue.OPENID));

	BearerAccessToken accessToken = new BearerAccessToken();

	given(this.clientRepository.findById(any(ClientID.class)))
			.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_BASIC));
	given(this.authenticationHandler.authenticate(any(ResourceOwnerPasswordCredentialsGrant.class)))
			.willReturn(new Subject("user"));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.willAnswer(returnsSecondArg());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED)
			.header("Authorization", clientAuth.toHTTPAuthorizationHeader());
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:23,代码来源:TokenEndpointTests.java


示例14: resourceOwnerPasswordCredentials_postAuth_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void resourceOwnerPasswordCredentials_postAuth_isOk() throws Exception {
	ClientSecretPost clientAuth = new ClientSecretPost(new ClientID("test-client"), new Secret("test-secret"));
	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
			new ResourceOwnerPasswordCredentialsGrant("user", new Secret("password")),
			new Scope(OIDCScopeValue.OPENID));

	BearerAccessToken accessToken = new BearerAccessToken();

	given(this.clientRepository.findById(any(ClientID.class)))
			.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_POST));
	given(this.authenticationHandler.authenticate(any(ResourceOwnerPasswordCredentialsGrant.class)))
			.willReturn(new Subject("user"));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.willAnswer(returnsSecondArg());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED);
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:22,代码来源:TokenEndpointTests.java


示例15: clientCredentials_basicAuth_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void clientCredentials_basicAuth_isOk() throws Exception {
	ClientSecretBasic clientAuth = new ClientSecretBasic(new ClientID("test-client"), new Secret("test-secret"));
	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
			new ClientCredentialsGrant(), new Scope("test"));

	BearerAccessToken accessToken = new BearerAccessToken();

	given(this.clientRepository.findById(any(ClientID.class)))
			.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_BASIC));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.willAnswer(returnsSecondArg());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED)
			.header("Authorization", clientAuth.toHTTPAuthorizationHeader());
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:20,代码来源:TokenEndpointTests.java


示例16: clientCredentials_postAuth_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void clientCredentials_postAuth_isOk() throws Exception {
	ClientSecretPost clientAuth = new ClientSecretPost(new ClientID("test-client"), new Secret("test-secret"));
	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
			new ClientCredentialsGrant(), new Scope("test"));

	BearerAccessToken accessToken = new BearerAccessToken();

	given(this.clientRepository.findById(any(ClientID.class)))
			.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_POST));
	given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
			.willAnswer(returnsSecondArg());
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED);
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:19,代码来源:TokenEndpointTests.java


示例17: refreshToken_basicAuth_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void refreshToken_basicAuth_isOk() throws Exception {
	ClientID clientId = new ClientID("test-client");

	ClientSecretBasic clientAuth = new ClientSecretBasic(clientId, new Secret("test-secret"));
	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
			new RefreshTokenGrant(new RefreshToken()));

	BearerAccessToken accessToken = new BearerAccessToken();

	given(this.clientRepository.findById(any(ClientID.class)))
			.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_BASIC));
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.refreshTokenStore.load(any(RefreshToken.class))).willReturn(new RefreshTokenContext(
			new RefreshToken(), clientId, new Subject("user"), new Scope(OIDCScopeValue.OPENID), null));

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED)
			.header("Authorization", clientAuth.toHTTPAuthorizationHeader());
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:22,代码来源:TokenEndpointTests.java


示例18: refreshToken_postAuth_isOk

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void refreshToken_postAuth_isOk() throws Exception {
	ClientID clientId = new ClientID("test-client");

	ClientSecretPost clientAuth = new ClientSecretPost(clientId, new Secret("test-secret"));
	TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
			new RefreshTokenGrant(new RefreshToken()));

	BearerAccessToken accessToken = new BearerAccessToken();

	given(this.clientRepository.findById(any(ClientID.class)))
			.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_POST));
	given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
	given(this.refreshTokenStore.load(any(RefreshToken.class))).willReturn(new RefreshTokenContext(
			new RefreshToken(), clientId, new Subject("user"), new Scope(OIDCScopeValue.OPENID), null));

	MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
			.contentType(MediaType.APPLICATION_FORM_URLENCODED);
	this.mvc.perform(request).andExpect(status().isOk());
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:21,代码来源:TokenEndpointTests.java


示例19: processAuthorization

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
protected AuthenticationMechanismOutcome processAuthorization(HttpServerExchange exchange) {
	String authorization = exchange.getRequestHeaders().getFirst(Headers.AUTHORIZATION);
	try {
		// TODO support passing in a JWT id_token instead of an oauth access token. This would bypass an expensive profile lookup and realize the goal of using
		// OpenID Connect tokens for SSO
		BearerAccessToken accessToken = BearerAccessToken.parse(authorization);
		UserInfoSuccessResponse info = fetchProfile(accessToken);
		// JWT idToken = JWTParser.parse(accessToken.getValue());
		// JWTClaimsSet claimsSet = new JWTClaimsSet.Builder().subject("demo").build();
		// PlainJWT idToken = new PlainJWT(claimsSet);
		// validateToken(idToken, exchange, false);
		return complete(info.getUserInfo().toJWTClaimsSet(), accessToken, null, exchange, false);
	} catch (Exception e) {
		OIDCContext oidcContext = exchange.getAttachment(OIDCContext.ATTACHMENT_KEY);
		oidcContext.setError(true);
		exchange.getSecurityContext().authenticationFailed("Unable to obtain OIDC JWT token from authorization header", mechanismName);
		return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
	}

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


示例20: updateUserInfoAsync

import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
public void updateUserInfoAsync() throws MalformedURLException, URISyntaxException
{
    final URI userInfoEndpoint = this.configuration.getUserInfoOIDCEndpoint();
    final IDTokenClaimsSet idToken = this.configuration.getIdToken();
    final BearerAccessToken accessToken = this.configuration.getAccessToken();

    this.executor.execute(new ExecutionContextRunnable(new Runnable()
    {
        @Override
        public void run()
        {
            try {
                updateUserInfo(userInfoEndpoint, idToken, accessToken);
            } catch (Exception e) {
                logger.error("Failed to update user informations", e);
            }
        }
    }, this.componentManager));
}
 
开发者ID:xwiki-contrib,项目名称:oidc,代码行数:20,代码来源:OIDCUserManager.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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