Giter VIP home page Giter VIP logo

spring-authorization-server's Introduction

Spring Authorization Server Gitter Build Status Revved up by Develocity

The Spring Authorization Server project, led by the Spring Security team, is focused on delivering OAuth 2.1 Authorization Server support to the Spring community.

This project replaces the Authorization Server support provided by Spring Security OAuth.

Feature Planning

This project uses GitHub Projects to prioritize the feature roadmap and help organize the project plan. The project board can be accessed here.

The feature list can be viewed in the reference documentation.

Support Policy

The Spring Authorization Server project provides software support through the VMware Tanzu OSS support policy. Commercial support, which offers an extended support period, is also available from VMware.

Getting Started

The first place to start is to read the OAuth 2.1 Authorization Framework to gain an in-depth understanding on how to build an Authorization Server. It is a critically important first step as the implementation must conform to the specification defined in the OAuth 2.1 Authorization Framework and the related specifications.

The second place to start is to become very familiar with the codebase in the following Spring Security modules:

A significant amount of effort was put into developing the Next Generation OAuth 2.0 Support in Spring Security. The goal is to leverage all the knowledge learned thus far and apply the same to the development of Spring Authorization Server.

Submitted work via pull requests should follow the same coding style/conventions and adopt the same or similar design patterns that have been established in Spring Security’s OAuth 2.0 support.

Documentation

Be sure to read the Spring Authorization Server Reference and Spring Security Reference, as well as the OAuth 2.0 Reference, which describes the Client and Resource Server features available.

JavaDoc is also available for the Spring Authorization Server API and Spring Security API.

Code of Conduct

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

Downloading Artifacts

See downloading Spring artifacts for Maven repository information.

Building from Source

Spring Authorization Server uses a Gradle-based build system. In the instructions below, ./gradlew is invoked from the root of the source tree and serves as a cross-platform, self-contained bootstrap mechanism for the build.

Prerequisites

Git and the JDK17 build.

Be sure that your JAVA_HOME environment variable points to the jdk17 folder extracted from the JDK download.

Check out sources

git clone [email protected]:spring-projects/spring-authorization-server.git

Install all spring-\* jars into your local Maven cache

./gradlew publishToMavenLocal

Compile and test; build all jars, distribution zips, and docs

./gradlew build

Discover more commands with ./gradlew tasks.

Getting Support

Contributing

Pull requests are welcome; see the contributor guidelines for details.

License

Spring Authorization Server is Open Source software released under the Apache 2.0 license.

spring-authorization-server's People

Contributors

721806280 avatar alek-sys avatar anoopgarlapati avatar appchemist avatar babuv2 avatar ddubson avatar drunkcattt avatar eleftherias avatar erichaagdev avatar esivakumar26 avatar github-actions[bot] avatar jgrandja avatar joshlong avatar jprinet avatar kehrlann avatar kratostaine avatar lspilca avatar martin-lindstrom avatar martinr0x avatar octopusthu avatar ovidiupopa07 avatar qeeqez avatar rlewczuk avatar rozagerardo avatar rwinch avatar shanman190 avatar sjohnr avatar uc4w6c avatar vonunige avatar walidell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-authorization-server's Issues

Epic: Setup repository

This epic groups the issues/tasks we should strive to complete before we publish the blog post.

Implement Authorization Model / Service

An authorization server needs to maintain existing authorizations between a client and resource owner. For example, when a resource owner grants access to a client (to access its protected resources), the authorization server must persist certain data in order to validate the authorization grant flow until it completes.

For example, during an authorization_code grant flow, the authorization server must persist the following data:

  • Certain Authorization Request parameters - OAuth2AuthorizationRequest
  • The identifier of the client - client_id
  • The identifier of the resource owner - current Authentication.getName()
  • The authorization code parameter
  • The granted access token - OAuth2AccessToken

The initial implementation should provide an in-memory implementation of OAuth2AuthorizationService, similar to InMemoryOAuth2AuthorizedClientService in the spring-security-oauth2-client module.

Implementation Requirements

  • InMemoryOAuth2AuthorizationService should store in a Map
  • OAuth2Authorization should be immutable
  • OAuth2Authorization.attributes should be used for storing data that is specific to an authorization grant, eg. authorization code parameter, OAuth2AuthorizationRequest, etc.
  • javadoc class and public methods
  • Unit tests

Specification References

4.1. Authorization Code Grant

Implement Client Authentication

The client must authenticate when calling the authorization server's token endpoint.

The OAuth2ClientAuthenticationFilter should be implemented as a Filter. The initial implementation should support HTTP Basic only.

Implementation Requirements

  • the Filter should process requests for the (default) path /oauth2/token and if HTTP Basic credentials are available in the request
  • the OAuth2ClientAuthenticationToken should be passed to the AuthenticationManager
  • the AuthenticationManager should be composed of OAuth2ClientAuthenticationProvider (in a later story)
  • the OAuth2ClientAuthenticationProvider should use the RegisteredClientRepository #40 to look up and validate the client credentials
  • the RegisteredClient should be returned in a new OAuth2ClientAuthenticationToken if the authentication succeeds
  • the Filter should save the OAuth2ClientAuthenticationToken in the SecurityContext
  • javadoc class and public methods
  • Unit tests

Specification References

2.3. Client Authentication
3.1. Token Endpoint
4.1. Authorization Code Grant
4.1.3. Access Token Request

Epic: Access Token Request Exchange

This epic will track the progress of the following feature:

Provide an implementation of the Access Token Request/Response (Exchange) for the authorization_code grant.

This epic is divided into multiple issues, in order to support parallel work streams.

#39 Implement Client Authentication
#67 Implement Token Endpoint
#68 Implement authorization_code AuthenticationProvider

See the ZenHub project board.

Add Empty Spring Boot Sample

The security team likes to start coding by placing all the code into a sample. We later extract it out into more framework-like code.

We should begin with an empty Spring Boot sample using the latest version of Gradle, which will eventually be the home for the project's minimal authorization server sample code.

For simplicity, Java classes should be placed into a package called sample.

At this point, this sample doesn't need any MVC endpoints or other configurations.

Add Token Endpoint

An authorization server should support a /token endpoint.

On this first iteration, the endpoint should support the client credentials grant gh-5. Namely, it should verify the grant_type parameter, and formulate a JWT based on the authenticated client.

Like the JWK Set Endpoint gh-2, this should be a Servlet Filter. It will likely sit later on in the Spring Security filter chain, post-authentication. As such, it can read the current authentication from the SecurityContextHolder.

The Nimbus library should be used for generating the JWT.

The JWT should contain jti, iss, sub, exp, and iat claims. Support for scp, aud, and nbf can be added later on.

The jti claim should be a GUID. The sub claim in the JWT should be the result of Authentication#getName. The exp claim should be a reasonable time in the future, and the iat claim should be the current time when the JWT is formulated. The iss claim could be hard-coded for now.

Multiple authentication handler abstraction

Hello there!

Where I work at our UAA must handle different ways of authentication. For example, with the grant Resource Owner Password Credentials our UAA offers 3 ways of authentication:

  • Default:
    • e-mail
    • password
  • Credentials:
    • user's social number, company registration number, etc
    • password
  • Delegation:
    • target a custom microservice to authenticate the user

For the grant Client Credentials it offer 2 ways:

  • Default backend client credentials
    • Authentication used between our microservices to call each other.
  • External client credentials
    • Third party application that communicate with our endpoints.

Using the legacy authorization server it was not nice to achieve this behavior. For example, the default email+password was a first class citizen, while other handlers had to "try hard" to be put to work.

Since the announcement of the authorization server discontinuation I wrote a new UAA for our company, and since I knew that there would be N ways of handling a specific grant type, I designed the application in order to facilitate the handler implementations.

But, now that Spring will create a new authorization server, I will try to use it instead of our own, even tho our own works perfectly fine. I just don't like reinventing the wheel.

Finally, my request is (and I guess this would already be on yours todo list) to abstract the authentication handlers so it would be easy to enhance the authorization server with N ways of authenticating a user (following the OAuth2 framework, of course). There should not be a first class citizen (looking at you UserDetailsService), but instead it should offer a nice abstraction for us to add the required ways of authentication.

This is just to clarify the idea, and by all means not how you should do it, but this is what we did in our UAA: The handlers must have some kind of way to answer the question: "should I handle this authentication request?". In order to answer that our handler interface has 2 methods:

  • Boolean canHandleGrantType(GrantType grantType)
  • Boolean canHandleAuthentication(TokenRequest tokenRequest, HttpServletRequest request)

The first one is the cheaper one. It will answer if it can (so far) handle the authentication grant type. For example, the DelegationAuthenticationHandler can handle GrantType.PASSWORD. So if the request is to authenticate client credentials, this handler would be skipped.

The second one will answer if it will handle that authentication based on those two parameters. For example, the DefaultAuthenticationHandler will handle it if the tokenRequest (which has the username) contains an username with @ and the http request doesn't have a delegation header.

And what about if 2 handlers can handle the same request? We defined that if the handler returns null it means "I didn't find the user, but other handler can try it". This will not stop the authentication process to try another available handler. If the handler throws a specific exception, this means that the authentication has failed and no more handlers should be tried.

From the example above we have 2 handlers. Which one should handle first? We control that with a simple @Order on our handlers.

Again, all this above is just to clarify the idea and the need for multiple handlers for every grant type.

Best regards.

Add Authorization Endpoint

An authorization server should support a /authorize endpoint.

The endpoint should support the authorization code grant. It should verify the response_type, client_id, redirect_uri, scope, and state parameters and formulate an authorization response. The redirect_uri, scope, and state parameters are optional but MUST be verified if present.

The authorization code response should consist of code and state parameters. The state parameter is optional but MUST be returned if provided in the authorization request.

Epic: Authorization Request Exchange

This epic will track the progress of the following feature:

Provide an implementation of the Authorization Request/Response (Exchange) for the authorization_code grant.

This epic is divided into multiple issues, in order to support parallel work streams.

#66 Implement Authorization Endpoint

See the ZenHub project board.

Add Resource Server Sample

Related to

It would be good to have a Resource Server sample that integrates with the authorization server sample. It should be quite similar to the Resource Server sample in Spring Security.

Like other samples, it should go into the samples directory. For simplicity, classes ought to be placed into a package called sample.

Given a valid token from the authorization server, the following test should pass:

this.mockMvc.perform(get("/")
        .header("Authorization", "Bearer " + token))
        .andExpect(status().isOk());

Implement Client Registration Model / Repository

An authorization server must provide a mechanism(s) for registering Clients.

The initial implementation should provide an in-memory implementation of RegisteredClientRepository, similar to InMemoryClientRegistrationRepository in the spring-security-oauth2-client module.

Implementation Requirements

  • InMemoryRegisteredClientRepository should store in a Map
  • RegisteredClient should provide a Builder, similar to ClientRegistration
  • RegisteredClient should be immutable
  • javadoc class and public methods
  • Unit tests

Specification References

2. Client Registration

Add Spring Security

This task will add Spring Security and ensure that all of the additional Filter's (gh-3, gh-5) are added to Spring Security in the proper places. We should start by using the existing Spring Security DSL (no need to create a custom DSL at this point).

When will it be stable to be used in commercial production environment?

Hi thanks for the newly rewritten spring security & spring auth server! I wonder when will it be stable to be used in commercial production environment?

In other words, if I need to use an OAuth solution in about 3 months (say, July), then which do you suggest:

  1. The deprecated Spring Security Oauth
  2. The new Spring Security, with 3rd party like Keycloak
  3. The new Spring Security, with this repo (stable?)

Thanks very much!

Add a Client Credentials Authentication Filter

When the token endpoint from gh-3 is invoked, we will need to validate client credentials (we can add other grant types later). For this issue, we can use a hard coded client credentials. The idea is to keep this as simple as possible. We should validate every aspect of the client credentials grant type.

We should produce tests that verify the behaviour

Setup Gradle build

We should setup the Gradle build to follow the conventions in Spring Security.

The gradle build should support the following modules:

core module with base package -> org.springframework.security.oauth2.server.authorization
config module with base package -> org.springframework.security.config
samples module

Epic: Client Authorization Model

This epic will track the progress of the following feature:

Provide a domain model for a client registration and authorization-related data associated between a client and a resource owner.

This epic is divided into multiple issues, in order to support parallel work streams.

#40 Implement Client Registration Model / Repository
#43 Implement Authorization Model / Service

See the ZenHub project board.

Drop Java 8 compatibility

Hi Everyone!

I understand that a big chunk of the Java community is still stuck on Java 8, but I wonder if there are any other reason why this project should still have compatibility to that version. As I understand it is not a supported version anymore and Java 11, the current LTS version has already been around for almost 2 years now. Wouldn't it be a good idea to default to Java 11 for this project?

Add JWK Set Endpoint

It would be quite useful to support an endpoint that would issue a JWK Set. Resource servers could retrieve this JWK Set for the purpose of validating JWTs.

For this task, we will avoid providing any of our own abstractions. The result should have a Filter that works directly with Nimbus to produce an response that looks something like:

{
    "keys": [
        {
            "alg": "RS256",
            "e": "AQAB",
            "kid": "257f6a5828d1e4a3a6a03fcd1a2461db9593e624",
            "kty": "RSA",
            "n": "kXPOxGSWngQ6Q02jhaJfzSum2FaU5_6e6irUuiwZbgUjyN2Q1VYHwuxq2o-aHqUhNPqf2cyCf2HspYwKAbeK9gFXqScrGLPW5pcquOWOVYUzPw87lBGH2fSxCYH35eB14wfLmF_im8DLTtZsaJvMRbqBgikM8Km2UA9ozjfK6E8pWW91fIT-ZF4Qy5zDkT3yX8EnAIMOuXg43v4t03FwFTyF4D9IET2ri2_n2qDhWTgtxJ0FHk3wG2KXdJIIVy2kUCTzMcZKaamRgUExt3Mu_z-2eyny8b6IdLPEIGF51VCgHebPQXE5iZmLGyw6M_pCApGJUw5GpXi6imo3pOvLjQ",
            "use": "sig"
        },
        {
            "alg": "RS256",
            "e": "AQAB",
            "kid": "6fcf413224765156b48768a42fac06496a30ff5a",
            "kty": "RSA",
            "n": "1sUr077w2aaSnm08qFmuH1UON9e2n6vDNlUxm6WgM95n0_x1GwWTrhXtd_6U6x6R6m-50mVS_ki2BHZ9Fj3Y9W5zBww_TNyNLp4b1802gbXeGhVtQMcFQQ-hFne5HaTVTi1y6QNbu_3V1NW6nNAbpR_t79l1WzGiN4ilFiYFU0OVjk7isf7Dv3-6Trz9riHBExl34qhriu3x5pfipPT1rf4J6jMroJTEeU6L7zd9k_BwjNtptS8wAenYaK4FENR2gxvWWTX40i548Sh-3Ffprlu_9CZCswCkQCdhTq9lo3DbZYPEcW4aOLBEi3FfLiFm-DNDK_P_gBtNz8gW3VMQ2w",
            "use": "sig"
        }
    ]
}

The keys that are used can be generated at startup or be constants. The Filter might look something like this:

public class JwkSetEndpoint implements Filter {
    private final JWKSet jwks;

    public JwkSetEndpoint() {
        this.jwks = ...
    }

    public void doFilter(...) {
        if (requestMatches(request)) {
            // ... serialize jwks into a response
        } else {
            chain.doFilter ...
        }
    }
}

A Filter is a good candidate since this will play nicely with Spring Security down the road. The constructor may change in the future as other abstraction layers become clearer.

We should then have a test that asserts the endpoint works properly.

Follow-up after announcement

After the Spring Authorization Server is announced via the blog post, we need to follow-up with:

  1. Update each of the 2 previous blog posts with link to new blog post:
  1. Post a comment to the original Support OAuth 2.0 Authorization Server issue to direct users to the new repository and then close the issue.

  2. Notify specific users in the community and direct them to the new repository.

  3. Provide a link to the new repository in the Spring Security OAuth project page.

  4. Add a note/link to the OAuth 2.0 Features Matrix

  5. Announce on Gitter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.