澄清id_token与access_token [英] Clarification on id_token vs access_token

查看:1918
本文介绍了澄清id_token与access_token的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OIDC和OAuth 2.0(使用Auth0)构建系统,并且不确定如何正确使用id_tokenaccess_token.或更确切地说,我对于将角色分配给我的设置中的各种服务感到困惑.

I'm building a system with OIDC and OAuth 2.0 (using Auth0), and I'm unsure how to properly use the id_token and access_token. Or rather, I'm confused about which roles to assign to the various services in my setup.

我有一个完全静态的前端应用程序(单页应用程序,HTML + JS,无后端),可确保使用针对Auth0的隐式流对用户进行身份验证.然后,前端应用程序从我也在构建的API中获取数据.

I have a fully static frontend-application (single-page app, HTML + JS, no backend) that ensures that the user is authenticated using the implicit flow against Auth0. The frontend-application then fetches data from an API that I am also building.

现在,对吗?

  • 前端SPA是OAuth 客户端应用程序
  • 我的API服务是OAuth 资源服务器
  • The frontend SPA is the OAuth client application
  • My API service is an OAuth resource server

...或:

  • 前端和我的API服务都是客户端应用程序

如果我的前端API和后端API都可以视为客户端,那么在从前端到后端的请求中使用id_token作为承载令牌时,我认为并没有真正的危害-这很有吸引力,因为这样我就可以验证后端上的签名令牌,我便拥有了所需用户的所有信息.但是,如果我的API被认为是资源服务器,则我可能应该使用access_token,但是随后我必须在每个API请求中都连接到Auth0的服务器,以验证令牌并获取基本用户信息,不是吗?

If both my frontend and backend API can be considered to be the client, I see no real harm in using the id_token as the bearer token on requests from my frontend to my backend - this is appealing because then I can simply verify the signed token on the backend, and I have all the information about the user that I need. However, if my API is considered a resource server, I should probably use the access_token, but then I have to connect to Auth0's servers on every API request to both verify the token, and get basic user info, won't I?

我已阅读似乎表明access_token是与我的API一起使用的唯一有效令牌.但是就像我说的那样,我不确定各个服务的作用.使用id_token很诱人,因为它不需要后端连接任何网络,并且包含我需要提取正确数据的信息.

I've read this which seems to suggest that the access_token is the only valid token for use with my API. But like I said, I'm not sure about the roles of the individual services. And using the id_token is tempting, because it requires no network connections on the backend, and contains information I need to extract the right data.

解决这个问题的正确方法是什么?

What is the right way to go about this?

推荐答案

您的前端是您的OAuth客户端应用程序,一旦它存储了令牌并可以对OAuth流进行操作.而且您的API服务是资源服务,因为它接受您的身份服务器发出的access_token.

Your frontent is your OAuth client application, once it stores the token and can take actions on the OAuth flow. And your API service is resource serve, because it accepts the access_token issued by your identity server.

我还要说,您的id_token代表已登录用户的身份,并且可能包含您应用程序的敏感数据. access_token就是您访问资源的凭据.

Also I would say that your id_token stands for the identification of the logged user and may contain sensitive data for your app. The access_token is standing as your credential to access a resouce.

最后,您将使用access_token来请求资源,并且,如果您需要登录用户(资源所有者)的特定数据,则可以从令牌端点请求ID令牌.

At the end you will use an access_token to request a resource, and than if you need specific data from the logged in user (resource owner), you may request the ID token from the token endpoint.

这篇关于澄清id_token与access_token的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆