I am trying to venture into the full-stack development realm during some of my free time, and I just have a few general questions about my current understanding of OAuth2. I am very green when it comes to this stuff, but I’ve watched some Udemy videos to gain a basic understanding.
Anyway… this project that I’m working on, I’m planning on having a custom authorization server, a resource server, and a single client (which will likely be a SPA). This authorization server will only allow the authorization code (probably with the PKCE extension) grant type. Which leads me to my first general question…
Intuitively, I assumed that the password grant type would be sufficient. As I’ve done more and more reading, it looks like this grant flow is not the way to go. As I understand it, using this flow would require the client to provide some form so that the user may login. Doing so gives the client access to user credentials, which very much defeats one of the purposes of OAuth2. I’m not sure this is an issue with what I’m developing, however, because I am creating the authorization server. I know by using this grant flow, I am not validating the client. Can someone explain how this might be an issue? Is there anything else I’m missing here? Everything I’ve read has deterred me from using this grant flow, which is mostly why I ended up deciding on the authorization code (w/ PKCE) flow.
So… assuming I go with this flow, my client should provide a login button. Pressing this login button will re-direct the client to a web page where the resource owner can authorize the client and provide user credentials. My authorization server will then validate these user credentials. I plan on storing user credentials in a database on the VM running the auth server. I don’t plan on allowing users to register an account. Instead, I’m just going to have a static list of account credentials in this database for people on my team. So I guess I’m just going to insert these accounts when the database is created? If so, how do I allow these users to change their passwords? I guess I’m thinking that initially these accounts will be assigned an e-mail, username, and random password that I can communicate with them. However, I’d like the user an option to change this random password to something more familiar. I don’t currently know how to do something like this with the OAuth2 implementation. Do I just provide a way in the client to change the password when the user is logged in? If so, doesn’t this somewhat defeat the purpose of using OAuth2 as now my client would have knowledge of the user credentials? If I were to do this, however, would this just be implemented as a POST request to a REST API at the auth server for updating the password?
I would start by using a free cloud provider as the Authorization Server. Have a look at the following tutorial of mine, which uses Authorization Code Flow + PKCE:
This sample uses AWS Cognito which is a fast option for getting started. It will enable you to create users – they will then be prompted to change the password on the first login.
The important points are these:
- Write simple standards based code in your apps and spend time learning the recommended flows and design ppatterns
- Once code is written you should be able to switch to a different Authorization Server later, if needed
- Avoid building your own Authorization Server, and use one that has been provided by specialists
You should only need Spring for the resource server (my API above uses Node.js). If you want an easy to follow Spring resource server sample maybe see this one.
Answered By – Gary Archer