kaqqao
kaqqao

Reputation: 15429

Log into a Spring Security application using a 3rd party OAuth2 server

I am working on a a web application secured by Spring Security. The new requirement is that the users can log in using an existing, 3rd party OAuth2 server, based on the authorization code grant, and use the API exposed by it. Think of my app as the e-banking site and 3rd party API as the banking back-end that my app calls to get a list of accounts for the user, for example.

Important points:

Questions:

Upvotes: 0

Views: 1740

Answers (1)

oceansize
oceansize

Reputation: 729

Yes, the login flow you explained is correct. This is exactly what OAuth2RestTemplate does - stores token in session.

But I don't understand your questions fully.

  1. Do you mean that Spring forces a user to be logged into Authorization Server before granting auth code? This is correct cause this is a user who allows your app to do operations on his behalf. How can he grant something without being logged in?

  2. I'm not sure where does Spring forces you to map user roles to scopes. Isn't it done in Authorization Server to limit scopes that can be granted by this user? But you're right - you can use token scopes to map them to internal roles in your app if needed.

  3. We used Cloudfoundry UAA to build OAuth2 Authorization Server and it has concept of auto-approved scopes (i.e. no explicit user approval is needed). You can take a look at that.

We had the same requirement and what we did was our own custom AuthenticationFilter(mapped to redirect_uri) that was exchanging received auth code to access token and then creating internal authentication with received token and also appropriate internal roles.

Upvotes: 1

Related Questions