Reputation: 1051
I've implemented a Spring
app with mongodb
and now I've implemented Rest authentication with Spring security and Mongodb, and now I have to add the Authorization
header, and it only shows the data from the api call if the Authorization
is ok, from now it's ok, but I'm wondering how do I get this value? I mean I want to make a Login to the app, should I have an authorization for this? If not, the login response should return this authorization to use it in next calls?
I also have read about aws token
also of oauth2
, but I really want to know the process, I mean, what's the flow a normal user can Log in to the app and then make calls with authorizations?
My platforms are :
DB -- MongoDB
Server -- Spring
Web -- Angular
App -- Android
This is a project for a Quiz game, that could support multigame options (more than 1 player playing at once)
So what I need to understand is from APP / WEB I have to make a call let's say api/v1/login and then send the user and password, ok, where's the part when I have to create the bcrypted and salt stuff to store it into db? Do I have to do it on the app and then send for instance the SHA stuff via JSON in the Login call or it's better to send the password to server so server does all of the stuff and store the stuff on the db?
Upvotes: 2
Views: 1886
Reputation: 6468
In the scenario you describe there is no sense to use neither OpenID Connect or OAuth2. There is a single server for both authentication and resources. The scenario could be roughly this:
Using SpringBoot you pretty much get it all for free. Unless you don't a have specific example I'd spare giving code snippets. You'll find wonderful and concise examples on the auth0 site.
Find here an Angular tutorial of how to send the access token along with your requests
Regarding your DB questions, a simple but valid scenario could be to store (in the DB) the encrypted password alongside your user. If a user logs in, he will send you the plain text password which you need to encrypt and compare it to the one you stored. Never store the plain text password, just use it for the login process. There are several best practices you might want to consider using passwords in Java applications.
Upvotes: 3
Reputation: 6954
I strongly suggest to you to use Spring Security, OAuth2 and JWT tokens in order to protect your REST API. The flow is the following:
Usually tokens have a time duration Basically OAuth2 defines 2 entities:
Moe information are available here https://www.baeldung.com/spring-security-oauth-jwt
UPDATE
Here https://github.com/angeloimm/spring_oauth I uploaded a simple sample og Spring (and not spring boot) OAuth JWT authentication based on DB H2.
You can download it and adapt it to mongodb. I think it's enough simple to adapt it. Sadly it's a very intense working period for me and I'm not able in doing it.
I hope it's useful
Angelo
Upvotes: 0