独立的资源服务器
Django OAuth工具包允许将 Authorization Server 以及 Resource Server 。基于 RFC 7662 Django OAuth工具包提供了符合RFC的自检端点。此外,Django OAuth工具包允许通过使用自检端点来验证访问令牌。
设置身份验证服务器
设置 Authorization Server 如中所述 教程 。为创建OAuth2访问令牌 Resource Server 并添加 introspection -范围到设置。
'SCOPES': {
'read': 'Read scope',
'write': 'Write scope',
'introspection': 'Introspect token scope',
...
},
这个 Authorization Server 将监听自省请求。终结点位于 oauth2_provider.urls AS /introspect/ 。
示例请求::
POST /o/introspect/ HTTP/1.1
Host: server.example.com
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer 3yUqsWtwKYKHnfivFcJu
token=uH3Po4KXWP4dsY4zgyxH
示例响应::
HTTP/1.1 200 OK
Content-Type: application/json
{
"active": true,
"client_id": "oUdofn7rfhRtKWbmhyVk",
"username": "jdoe",
"scope": "read write dolphin",
"exp": 1419356238
}
设置资源服务器
Setup the Resource Server like the Authorization Server as described in the 教程.
Add RESOURCE_SERVER_INTROSPECTION_URL and either RESOURCE_SERVER_AUTH_TOKEN
or RESOURCE_SERVER_INTROSPECTION_CREDENTIALS as a (id,secret) tuple to your settings.
The Resource Server will try to verify its requests on the Authorization Server.
OAUTH2_PROVIDER = {
...
'RESOURCE_SERVER_INTROSPECTION_URL': 'https://example.org/o/introspect/',
'RESOURCE_SERVER_AUTH_TOKEN': '3yUqsWtwKYKHnfivFcJu', # OR this but not both:
# 'RESOURCE_SERVER_INTROSPECTION_CREDENTIALS': ('rs_client_id','rs_client_secret'),
...
}
RESOURCE_SERVER_INTROSPECTION_URL 定义自检终结点和 RESOURCE_SERVER_AUTH_TOKEN 一个身份验证令牌,用于根据 Authorization Server 。根据RFC 7662的允许,某些外部OAuth 2.0服务器支持HTTP基本身份验证。对于这些,请使用: RESOURCE_SERVER_INTROSPECTION_CREDENTIALS=('client_id','client_secret') 而不是 RESOURCE_SERVER_AUTH_TOKEN 。