Skip to content

Provide support for OAuth 2.0 #4238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed

Conversation

jgrandja
Copy link
Contributor

@jgrandja jgrandja commented Mar 7, 2017

Provide support for an OAuth 2.0 Client.

@jgrandja jgrandja added this to the 5.0.0.M1 milestone Mar 7, 2017
@jgrandja jgrandja added the in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) label Mar 7, 2017
@rwinch
Copy link
Member

rwinch commented Mar 16, 2017

General

  • Do all assertions at the top of the constructor rather than assert, assign, assert, assign, ...
  • I'm confused why AuthorizationRequestAttributes is in oauth2-core and AuthorizationRequestRepository is in oauth2-client

spring-security-oauth2-core

  • I think that AbstractToken should probably have constructs on it for expiration. If not, we need to have expiration added to RefreshToken
  • the openid package should be a child of oauth2

spring-security-oauth2-client

oauth2login

  • Please add a README with directions on setup oauth2login Where to go to get client-id, client-secret, etc for each provider.
  • email is displayed as empty for github client
  • Running in STS with Buildship gives an error
java.lang.NoSuchMethodError: ch.qos.logback.core.util.Loader.getResourceOccurrenceCount(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/util/Set;
	at ch.qos.logback.classic.util.ContextInitializer.multiplicityWarning(ContextInitializer.java:160)
	at ch.qos.logback.classic.util.ContextInitializer.statusOnResourceSearch(ContextInitializer.java:183)
	at ch.qos.logback.classic.util.ContextInitializer.getResource(ContextInitializer.java:141)
	at ch.qos.logback.classic.util.ContextInitializer.findURLOfDefaultConfigurationFile(ContextInitializer.java:130)
	at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
	at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
	at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:274)
	at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:190)
	at org.springframework.security.samples.OAuth2LoginApplication.main(OAuth2LoginApplication.java:31)

@rwinch rwinch self-requested a review March 16, 2017 17:37
@@ -29,7 +29,7 @@
*/
public class JavaVersionTests {

private static final int JDK6_CLASS_VERSION = 50;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All infrastructure changes (i.e. updating to Java 8) should be in a distinct commit

@@ -0,0 +1,19 @@
apply from: BOOT_SAMPLE_GRADLE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only use tabs

*/
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration should be simplified

  • The customization of ClientRegistration for github needs to go away some how. Perhaps rather than customizing it in the configure any customization should be done in the bean definition itself.
  • I don't like the boilerplate code here (copy paste, modify for each provider we are leveraging, profiles, etc). Some of this might be necessary in a standard application, but it should not be required in a Boot application. AutoConfiguraiton can live in this sample (within a separate package) until we can get it into boot. In the end we should only have the yml file (the entire SecurityConfig should be removed).
  • Now that this is getting merged we should add the oauthLogin to HttpSecurity

@@ -0,0 +1,34 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably belongs in oauth2-client rather than oauth2-core

import org.springframework.security.core.Authentication;

/**
* Root exception for all OAuth2-related general errors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true because as the NOTE mentions, OAuth2AuthenticationException is also used. I think we should try to rename this to be more exact. Perhaps OAuth2AuthorizationException (does that work for the use cases it is intended for)?

filterChain.doFilter(request, response);
}

private void obtainAuthorization(HttpServletRequest request, HttpServletResponse response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps rename to authorizationRequestRedirect

response.sendError(HttpServletResponse.SC_BAD_REQUEST, failed.getMessage());
}

private String normalizeUri(String uri) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than implement this yourself, use UriComponentsBuilder


@Override
public final void afterPropertiesSet() {
Assert.notEmpty(this.clientRegistrationRepository.getRegistrations(), "clientRegistrationRepository cannot be empty");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate not empty at time of creating the ClientRegistrationRepository

/**
* @author Joe Grandja
*/
public interface AuthorizationRequestRepository {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass in the HttpServletResponse so that cookies could be used

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a data object rather than having lots of params

/**
* @author Joe Grandja
*/
public interface AuthorizationGrantTokenExchanger<T extends AuthorizationGrantAuthenticationToken> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to take a generic argument? Can it just always use AuthorizationCodeGrantAuthenticationToken

@jgrandja
Copy link
Contributor Author

Closing with new PR to follow

@jgrandja jgrandja closed this Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants