Should I send the id token from my SPA to my rest backend?

自作多情 提交于 2019-12-05 10:24:41

I went through Authenticate with a backend server as you have pointed out. As it suggest, one can use id token to authenticate against backend server. Which not only recomend by Google but some other entities as well. But id token is intended for relying party (client) to validate and authenticate the end user. Access token is the token that should be used to access resources.

One alternative you could consider is the use of user info endpoint defined by OpenID Connect specification.

User info endpoint

The UserInfo Endpoint is an OAuth 2.0 Protected Resource that returns Claims about the authenticated End-User. To obtain the requested Claims about the End-User, the Client makes a request to the UserInfo Endpoint using an Access Token obtained through OpenID Connect Authentication. These Claims are normally represented by a JSON object that contains a collection of name and value pairs for the Claims.

Google do provide user info endpoint. Their documentation's Obtaining user profile information sectioon explains about the endpoint, how to call it and response details.

To obtain additional profile information about the user, you can use the access token (which your application receives during the authentication flow) and the OpenID Connect standard:

And a succesfull details will reveal end user infromation which has a format explained in People: getOpenIdConnect format.

This way you avoid exposing id token to other parties. And your backend can use the access token to access these information to detect end user and authenitcate based on that.

Regardless of these alternative approaches, id token is meant to be used for authentication. So passing it to server and use claims to identify end user and authenticate on token validity is fine as long as you protect id token.

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