How to authentication and authorization using JWT in SSO for microservices?

点点圈 提交于 2019-12-12 19:07:39

问题


We are using spring API security in a spring boot application.

We have implemented two level of security which is page level and also API level. We support both login from our own application and SSO login. we also skiping two apis from authN ( api/login and /api/token)

I have few questions regarding the architecture.

Number 1:

We have our own login which will get input as userName and password for authentication and returns an access token.

How can I add SSO(Single Sign On) to this API?

Number 2:

How to persist the token and how to use the refresh token.

When the user get logged in, I will create an access token and a refresh token. The access token will be sent back to the UI and the refresh token will be in the DB/cache. When the user calls any API from his browser, he will send the access token with the ajax request, the filter validates the token and sends the responce after validating the token in the preAuthN service.

My question is, if the access token supposedly is expired, then how can I generate my new access token using the refresh token?

Solution 1: once the server receives the access token, validate that and if the access token expired, from the server itself call /api/token to renew acess token and process the reques and send back the responce with the token

Solution 2: Once the server receives the access token, validate that and if the access token expired, send the acknowledgement to the browser and the browser will handle it somehow to generate a new access token

Or are there any better solutions?

来源:https://stackoverflow.com/questions/43589951/how-to-authentication-and-authorization-using-jwt-in-sso-for-microservices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!