I'm pretty new to OAuth 2.0
and OpenID Connect
and I have trouble understanding some parts of the flow (or what best practices should I use)...
Sorry for the lengthy post :)
My Setup:
An
OP
(OpenID Provider) that is basically anexpress
server that usesoauth2orize-openid
andpassport
to authenticate and authorize users. Let's call ithttp://authserver.com
A
Single page application
(react+webpack) that needs to authenticate users against myOP
, Let's call ithttp://my-spa.com
Since it's an SPA (statically served by webpack) I have to use Implicit Flow
.
My Questions
Once the user navigates to http://my-spa.com
, the application is loaded, then it checks against the localStorage
whether an id_token
exists.
no id_token
in localStorage
on load :
- Since there's no token, I redirect to
http://authserver.com/dialog/authorize
response_type=id_token
scope=openid profile
- Once the user successfully authenticated and authorized,
authserver
redirects back tomy-spa
with theid_token
in the URI Fragment - I store the
id_token
in thelocalStorage
and the user can start using the app.
there's an id_token
in localStorage
on load
The user closed the browser and opened it again. This is where I'm having a trouble to understand what to do. Since there's already a token (from previous login), I need to check if it's valid.
What are the best practices to do so? Here's what I'm thinking would be correct:
- Redirecting to
http://authserver.com/dialog/authorize
using :prompt=none
id_token_hint=CURRENT_TOKEN
- once
OP
receives this request, it should verify JWT signature, try to auto-approve the user and redirect back with a new JWT.
token get's expired after some time
Let's say a logged-in user has it's JWT expired, when should it ask for a new one? What should trigger the renewal?
what are the /tokeninfo
or /userinfo
for?
From my understanding, JWT stores all the data required to identify a user. However I've seen examples calling /tokeninfo
or /userinfo
.
If I already have the sub
id, are these endpoints just for verifying the token (assuming I need nothing but the subject's id)?
JWT signature verification
Beside the OP
, should my-spa
verify the JWT signature (with a public key perhaps)?
re-using this token to access a REST API of a third service
If I have another web service api, call it http://my-service.com/api
which needs to know which user invoked it from my SPA, these are the steps I believe I need to perform:
- Add the
id_token
as aBearer
token to each ajax request my-service.com
should validate the JWT signature (with a public key?) and decide whether to allow or deny access to the protected resource
Any help will be appreciated!