Java Code Examples for org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails#setUseCurrentUri()

The following examples show how to use org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails#setUseCurrentUri() . 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
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public AuthorizationCodeResourceDetails authorizationCode() {
    AuthorizationCodeResourceDetails resourceDetails = new AuthorizationCodeResourceDetails();

    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setClientSecret("123456");
    resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
    resourceDetails.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    resourceDetails.setScope(Arrays.asList("read_profile"));
    resourceDetails.setPreEstablishedRedirectUri(("http://localhost:9000/callback"));
    resourceDetails.setUseCurrentUri(false);
    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);

    return resourceDetails;
}
 
Example 2
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails authorizationCode() {
    AuthorizationCodeResourceDetails resourceDetails = new AuthorizationCodeResourceDetails();

    //@formatter:off
    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setClientSecret("123456");
    resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
    resourceDetails.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    resourceDetails.setScope(Arrays.asList("read_profile"));
    resourceDetails.setPreEstablishedRedirectUri(("http://localhost:9000/callback"));
    resourceDetails.setUseCurrentUri(false);
    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);
    //@formatter:on

    return resourceDetails;
}
 
Example 3
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails authorizationCode() {
    AuthorizationCodeResourceDetails resourceDetails = new AuthorizationCodeResourceDetails();

    //@formatter:off
    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setClientSecret("123456");
    resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
    resourceDetails.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    resourceDetails.setScope(Arrays.asList("read_profile"));
    resourceDetails.setPreEstablishedRedirectUri(("http://localhost:9000/callback"));
    resourceDetails.setUseCurrentUri(false);
    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);
    //@formatter:on

    return resourceDetails;
}
 
Example 4
Source File: Oauth2ClientRestTemplate.java    From spring-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 演示 grant_type=authorization_code 时,获取资源的方法
 * -
 *
 * @param client_id
 * @param client_secret     取决于 AuthorizationServer 设置,如果 client 设置了secret,则此项参数为必需,否则可以没有
 * @param access_token_uri
 * @param authorization_uri
 * @param scope
 * @return
 */

public OAuth2RestOperations authorizationCodeRestTemplate(String client_id, String client_secret, String authorization_uri, String access_token_uri, String... scope) {

    // 防止 url 写错
    if (!access_token_uri.contains("token") || !authorization_uri.contains("authorize"))
        throw new RuntimeException("uri is wrong :  access_token_uri = " + access_token_uri + " , authorization_uri" + authorization_uri);


    AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
    details.setId("1");
    details.setClientId(client_id);
    if (client_secret != null && !client_secret.isEmpty())
        details.setClientSecret(client_secret);
    details.setAccessTokenUri(access_token_uri);
    details.setUserAuthorizationUri(authorization_uri);
    details.setUseCurrentUri(true); //将当前请求的 uri 作为参数 redirect_uri 接受返回值。设置为 faslse 是,需要设置 redirect_uri 参数, details.setPreEstablishedRedirectUri("http://anywhere");
    details.setScope(Arrays.asList(scope));
    return new OAuth2RestTemplate(details, oAuth2ClientContext);
}
 
Example 5
Source File: OAuth2Configuration.java    From oauth2lab with MIT License 5 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails authorizationCode() {
    AuthorizationCodeResourceDetails details =
        new AuthorizationCodeResourceDetails();
    details.setId("oauth2server");
    details.setClientId("clientapp");
    details.setClientSecret("112233");
    details.setUseCurrentUri(true);
    details.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    details.setAccessTokenUri("http://localhost:8080/oauth/token");
    return details;
}
 
Example 6
Source File: FacebookConfiguration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails resourceDetails() {
    AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
    details.setClientId(properties.getClientId());
    details.setClientSecret(properties.getClientSecret());
    details.setUserAuthorizationUri(properties.getAppAuthorizationUri());
    details.setAccessTokenUri(properties.getAppTokenUri());
    details.setPreEstablishedRedirectUri(properties.getRedirectUri());
    details.setScope(Arrays.asList("email", "public_profile"));
    details.setClientAuthenticationScheme(AuthenticationScheme.query);
    details.setUseCurrentUri(false);
    return details;
}
 
Example 7
Source File: GoogleConfiguration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails resourceDetails() {
    AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
    details.setClientId(properties.getClientId());
    details.setClientSecret(properties.getClientSecret());

    // URLs retrieved from https://accounts.google.com/.well-known/openid-configuration
    details.setUserAuthorizationUri("https://accounts.google.com/o/oauth2/v2/auth");
    details.setAccessTokenUri("https://www.googleapis.com/oauth2/v4/token");
    details.setPreEstablishedRedirectUri("http://localhost:8080/google/callback");
    details.setScope(Arrays.asList("openid", "email", "profile"));
    details.setUseCurrentUri(false);
    return details;
}
 
Example 8
Source File: GoogleConfiguration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails resourceDetails() {
    AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
    details.setClientId(properties.getClientId());
    details.setClientSecret(properties.getClientSecret());

    // URLs retrieved from https://accounts.google.com/.well-known/openid-configuration
    details.setUserAuthorizationUri("https://accounts.google.com/o/oauth2/v2/auth");
    details.setAccessTokenUri("https://www.googleapis.com/oauth2/v4/token");
    details.setPreEstablishedRedirectUri("http://localhost:8080/google/callback");
    details.setScope(Arrays.asList("openid", "email", "profile"));
    details.setUseCurrentUri(false);

    return details;
}
 
Example 9
Source File: OAuth2Configuration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails authorizationCode() {
    AuthorizationCodeResourceDetails details =
        new AuthorizationCodeResourceDetails();
    details.setId("oauth2server");
    details.setClientId("clientapp");
    details.setClientSecret("123");
    details.setUseCurrentUri(true);
    details.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    details.setAccessTokenUri("http://localhost:8080/oauth/token");
    return details;
}
 
Example 10
Source File: OAuth2Shim.java    From shimmer with Apache License 2.0 5 votes vote down vote up
public OAuth2ProtectedResourceDetails getResource() {

        AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();

        resource.setAccessTokenUri(getAccessTokenUrl());
        resource.setUserAuthorizationUri(getUserAuthorizationUrl());
        resource.setClientId(getClientSettings().getClientId());
        resource.setScope(getClientSettings().getScopes());
        resource.setClientSecret(getClientSettings().getClientSecret());
        resource.setUseCurrentUri(true);

        return resource;
    }