Java Code Examples for org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider

The following examples show how to use org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public OAuth2RestTemplate getUserInfoRestTemplate() {
	if (this.oauth2RestTemplate == null) {
		this.oauth2RestTemplate = createOAuth2RestTemplate(
				this.details == null ? DEFAULT_RESOURCE_DETAILS : this.details);
		this.oauth2RestTemplate.getInterceptors().add(new AcceptJsonRequestInterceptor());
		AuthorizationCodeAccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider();
		accessTokenProvider.setTokenRequestEnhancer(new AcceptJsonRequestEnhancer());
		this.oauth2RestTemplate.setAccessTokenProvider(accessTokenProvider);
		if (!CollectionUtils.isEmpty(this.customizers)) {
			AnnotationAwareOrderComparator.sort(this.customizers);
			for (UserInfoRestTemplateCustomizer customizer : this.customizers) {
				customizer.customize(this.oauth2RestTemplate);
			}
		}
	}
	return this.oauth2RestTemplate;
}
 
Example 2
Source Project: DAFramework   Source File: OAuth2Util.java    License: MIT License 6 votes vote down vote up
public static Filter wechat(AuthorizationCodeResourceDetails client, ResourceServerProperties resourceServerProperties, String path, OAuth2ClientContext oauth2ClientContext) {
	OAuth2ClientAuthenticationProcessingFilter oAuth2ClientAuthenticationFilter = new OAuth2ClientAuthenticationProcessingFilter(path);

	OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(client, oauth2ClientContext);
	AuthorizationCodeAccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider();
	accessTokenProvider.setAuthorizationRequestEnhancer((request, resource, form, headers) -> {
		form.set("appid", resource.getClientId());
		form.set("secret", resource.getClientSecret());
		form.set("scope", "snsapi_userinfo");
		form.set("response_type", "code");
		form.set("#wechat_redirect", "");
	});
	accessTokenProvider.setMessageConverters(converters());
	oAuth2RestTemplate.setAccessTokenProvider(accessTokenProvider);

	oAuth2RestTemplate.setRetryBadAccessTokens(true);
	oAuth2ClientAuthenticationFilter.setRestTemplate(oAuth2RestTemplate);

	UserInfoTokenServices tokenServices = new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(), client.getClientId());
	tokenServices.setRestTemplate(oAuth2RestTemplate);
	oAuth2ClientAuthenticationFilter.setTokenServices(tokenServices);
	return oAuth2ClientAuthenticationFilter;
}
 
Example 3
Source Project: OAuth-2.0-Cookbook   Source File: FacebookConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public OAuth2RestTemplate restTemplate(OAuth2ClientContext context) {
    OAuth2RestTemplate rest = new OAuth2RestTemplate(resourceDetails(), context);
    rest.setAccessTokenProvider(
        new AccessTokenProviderChain(
            Arrays.asList(new AuthorizationCodeAccessTokenProvider())));
    return rest;
}
 
Example 4
Source Project: OAuth-2.0-Cookbook   Source File: GoogleConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public OAuth2RestTemplate restTemplate(OAuth2ClientContext context) {
    OAuth2RestTemplate rest = new OAuth2RestTemplate(resourceDetails(), context);
    AccessTokenProviderChain providerChain = new AccessTokenProviderChain(
            Arrays.asList(new AuthorizationCodeAccessTokenProvider()));
    rest.setAccessTokenProvider(providerChain);
    return rest;
}
 
Example 5
Source Project: OAuth-2.0-Cookbook   Source File: GoogleConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public OAuth2RestTemplate restTemplate(OAuth2ClientContext context) {
    OAuth2RestTemplate rest = new OAuth2RestTemplate(resourceDetails(), context);
    AccessTokenProviderChain providerChain = new AccessTokenProviderChain(
            Arrays.asList(new AuthorizationCodeAccessTokenProvider()));
    rest.setAccessTokenProvider(providerChain);
    return rest;
}
 
Example 6
Source Project: shimmer   Source File: RunkeeperShim.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public AuthorizationCodeAccessTokenProvider getAuthorizationCodeAccessTokenProvider() {

    AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider();
    provider.setTokenRequestEnhancer(new RunkeeperTokenRequestEnhancer());
    return provider;
}
 
Example 7
Source Project: OAuth-2.0-Cookbook   Source File: ClientConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
public OAuth2RestTemplate oauth2RestTemplate() {

    OAuth2ProtectedResourceDetails resourceDetails = authorizationCode();

    OAuth2RestTemplate template = new OAuth2RestTemplate(resourceDetails,
            oauth2ClientContext);

    AccessTokenProviderChain provider = new AccessTokenProviderChain(
            Arrays.asList(new AuthorizationCodeAccessTokenProvider()));

    provider.setClientTokenServices(clientTokenServices);
    template.setAccessTokenProvider(provider);

    return template;
}
 
Example 8
Source Project: OAuth-2.0-Cookbook   Source File: ClientConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
public OAuth2RestTemplate oauth2RestTemplate() {

    OAuth2ProtectedResourceDetails resourceDetails = authorizationCode();

    OAuth2RestTemplate template = new OAuth2RestTemplate(resourceDetails,
            oauth2ClientContext);

    AccessTokenProviderChain provider = new AccessTokenProviderChain(
            Arrays.asList(new AuthorizationCodeAccessTokenProvider()));

    provider.setClientTokenServices(clientTokenServices);
    template.setAccessTokenProvider(provider);

    return template;
}
 
Example 9
Source Project: spring-boot-demo   Source File: AuthorizationCodeGrantTests.java    License: MIT License 4 votes vote down vote up
@Test
void testAttemptedTokenAcquisitionWithNoRedirect() {
    AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider();
    assertThrows(UserRedirectRequiredException.class,
        () -> provider.obtainAccessToken(resource, new DefaultAccessTokenRequest()));
}
 
Example 10
Source Project: shimmer   Source File: FitbitShim.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public AuthorizationCodeAccessTokenProvider getAuthorizationCodeAccessTokenProvider() {

    return fitbitAuthorizationCodeAccessTokenProvider;
}
 
Example 11
Source Project: shimmer   Source File: IHealthShim.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public AuthorizationCodeAccessTokenProvider getAuthorizationCodeAccessTokenProvider() {

    return new IHealthAuthorizationCodeAccessTokenProvider();
}
 
Example 12
Source Project: shimmer   Source File: JawboneShim.java    License: Apache License 2.0 4 votes vote down vote up
public AuthorizationCodeAccessTokenProvider getAuthorizationCodeAccessTokenProvider() {
    return new JawboneAuthorizationCodeAccessTokenProvider();
}
 
Example 13
Source Project: shimmer   Source File: MisfitShim.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public AuthorizationCodeAccessTokenProvider getAuthorizationCodeAccessTokenProvider() {

    return new MisfitAuthorizationCodeAccessTokenProvider();
}
 
Example 14
Source Project: shimmer   Source File: MovesShim.java    License: Apache License 2.0 4 votes vote down vote up
public AuthorizationCodeAccessTokenProvider getAuthorizationCodeAccessTokenProvider() {

        AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider();
        provider.setTokenRequestEnhancer(new MovesAccessTokenRequestEnhancer());
        return provider;
    }
 
Example 15
Source Project: shimmer   Source File: GoogleFitShim.java    License: Apache License 2.0 2 votes vote down vote up
public AuthorizationCodeAccessTokenProvider getAuthorizationCodeAccessTokenProvider() {

        return new GoogleAuthorizationCodeAccessTokenProvider();
    }
 
Example 16
Source Project: shimmer   Source File: OAuth2Shim.java    License: Apache License 2.0 votes vote down vote up
protected abstract AuthorizationCodeAccessTokenProvider getAuthorizationCodeAccessTokenProvider();