简体   繁体   English

OAuth 2 - 如何定义动态资源授权?

[英]OAuth 2 - how to define dynamic resource authorization?

As a resource server, I'd like to give users more control over their resources.作为资源服务器,我想让用户更多地控制他们的资源。

For example, consider I have a cloud file system supporting OAuth 2.例如,考虑我有一个支持 OAuth 2 的云文件系统。

The user may provide permission to access the files to a client on his behalf.用户可以代表他向客户提供访问文件的权限。

I'd like the resource server to offer access to specific folder, for example, just photos and not documents.我希望资源服务器提供对特定文件夹的访问,例如,只有照片而不是文档。

The names of the folders is a dynamic resource, as it varies among users.文件夹的名称是一种动态资源,因为它因用户而异。

How can I handle dynamic resource authorization?如何处理动态资源授权? Dynamic scopes?动态范围?

Also, if the scope is dynamic, how does the client know to request it?此外,如果范围是动态的,客户端如何知道请求它?

* Couldn't find it in the spec :( * 在规范中找不到它:(

The document rfc6749 which is the OAuth 2.0 spec, defines a way to extend OAuth 2 by using additional parameters(rfc6749#section-8.2).作为 OAuth 2.0 规范的文档 rfc6749 定义了一种通过使用附加参数来扩展 OAuth 2 的方法(rfc6749#section-8.2)。 So, if you want to solve this with OAuth, you could use this approach or something similar:所以,如果你想用 OAuth 解决这个问题,你可以使用这种方法或类似的方法:

  • you define a new parameter for the Authorization Request to specify a resource(EX: folderID=XXXXX)您为授权请求定义一个新参数以指定资源(例如:folderID=XXXXX)
  • During the Authorization request, a client can OPTIONALLY specify a resource by using the new parameter在授权请求期间,客户端可以使用新参数选择性地指定资源
  • If the parameter is specified, your Authorization Server will generate a "dynamic scope" which must be signed by the Resource Owner如果指定了该参数,您的授权服务器将生成一个必须由资源所有者签名的“动态范围”
  • if the parameter is not specified, the Resource Owner can select the resource he wants to share, and the Authorization server can generate the related "dynamic scope" (This scenario implies that the resource server is involved somehow during the Authorization flow)如果不指定参数,Resource Owner可以选择自己想要共享的资源,Authorization服务器可以生成相关的“动态范围”(这个场景意味着在Authorization流程中资源服务器以某种方式参与)
  • When the scopes are defined and signed by the Resource owner they are communicated to the Client (it should be able to derive the resource ID from the scope if the latter has been defined by Resource Owner)当范围由资源所有者定义和签名时,它们将传达给客户端(如果后者已由资源所有者定义,则它应该能够从范围派生资源 ID)
  • When the Client asks for a resource, the resource server also has to make sure that the scope includes the requested resource当客户端请求资源时,资源服务器还必须确保范围包括请求的资源

Bear in Mind that such approach works better if the amount of resources per user is not very big (otherwise you can be flooded of scopes).请记住,如果每个用户的资源量不是很大(否则您可能会被范围淹没),这种方法效果更好。

Another method could be to add an extra layer of Authorization behind the OAuth Layer.另一种方法是在 OAuth 层后面添加额外的授权层。 This additional layer keeps track of the relation client/accessible resources.这个附加层跟踪关系客户端/可访问资源。

Just recently I had to familiarize myself with OAuth/OIDC, and now I am facing the same question - here's what I could think of so far -就在最近,我不得不熟悉 OAuth/OIDC,现在我面临着同样的问题——这是我目前能想到的——

  • You surely have a reason to externalize security (authN, authZ) - that's why you use OAuth.您肯定有理由将安全性外部化(authN、authZ)——这就是您使用 OAuth 的原因。 Do you really want your Authorization Server to know about the resources you have in your application?你真的想让你的授权服务器知道你在你的应用程序中拥有的资源吗?
  • Scopes - as far as I understood - control access to APIs, not 'resources' in the standard meaning - even though I read about 'resource' typed scopes, but those were again giving access to an API.作用域——据我所知——控制对 API 的访问,而不是标准含义中的“资源”——即使我读到了“资源”类型的作用域,但那些再次授予对 API 的访问权限。
  • If you have resources (files) you want to control access to, you'll probably better off handling it inside your application - and optionally request the list of known clients from the Auth Server, if you have to.如果您有想要控制访问权限的资源(文件),最好在应用程序中处理它 - 如果必须,还可以选择从身份验证服务器请求已知客户端的列表。

This is the way I am going to try doing it for my own app anyway - it is indeed surprising not to find any resources about this online.无论如何,这就是我要尝试为我自己的应用程序执行此操作的方式 - 没有在网上找到有关此的任何资源确实令人惊讶。

Resurrecting a pretty old question here, but I think the problem is still current.在这里复活一个很老的问题,但我认为这个问题仍然存在。

One useful detail to bear in mind is that the scope requested by the client and the scope allowed by the Resource Owner don't have to be equal.要记住的一个有用的细节是客户端请求的范围和资源所有者允许的范围不必相等。 In fact, the scope allowed by the RO doesn't even have to be a subset of the requested scope.事实上,RO 允许的范围甚至不必是请求范围的子集。

In your case, the scope allowed by the RO can be a set of resource URLs, selected by the RO at grant step depending on the requested scope.在您的情况下,RO 允许的范围可以是一组资源 URL,由 RO 在授权步骤根据请求的范围选择。 Then, by looking at the values in the access token and understanding their meaning, the Resource Server will be able to serve the requested resources dynamically.然后,通过查看访问令牌中的值并理解它们的含义,资源服务器将能够动态地为请求的资源提供服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DRF 和 Oauth2:创建资源和授权服务器 - DRF and Oauth2: creating resource and authorization servers OAuth 2:分离资源服务器和授权服务器 - OAuth 2: separating resource server and authorization server 分离OAuth2授权服务器和资源服务器 - Separating OAuth2 Authorization Server and Resource Server Spring OAuth:具有授权服务器后端的资源服务器 - Spring OAuth: Resource Server with Authorization Server backend Spring OAuth2资源和授权服务器 - Spring OAuth2 Resource and Authorization servers 资源服务器应如何验证授权服务器颁发的 oauth 不记名令牌? - How resource server should validate oauth bearer token that issued by Authorization Server? 如何实现 OAuth 资源服务器来验证来自不同授权服务器的访问令牌? - How to implement an OAuth resource server to validate access tokens from different authorization servers? 如何在使用 Bearer 令牌作为授权标头调用资源 API 时在客户端/浏览器中保存 OAuth2 访问令牌 - How to save OAuth2 access token in Client / Browser when calling Resource APIs with Bearer token as Authorization Header OAuth如何处理授权? - How does OAuth handle authorization? Spring-boot oauth2拆分授权服务器和资源服务器 - Spring-boot oauth2 splitting authorization server and resource server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM