元数据终结点
OAuth2.0授权服务器元数据 (RFC8414) 端点提供授权服务器的元数据。由于元数据结果可以是OAuthlib的Endpoint(请参见 预配置的一体机服务器 ),MetadataEndpoint的类接受参数中的终结点列表,并聚合响应中的元数据。
参见下面的用法示例 bottle-oauthlib 在使用 LegacyApplicationServer (授予密码)终结点:
import bottle
from bottle_oauthlib.oauth2 import BottleOAuth2
from oauthlib import oauth2
app = bottle.Bottle()
app.authmetadata = BottleOAuth2(app)
oauthlib_server = oauth2.LegacyApplicationServer(oauth2.RequestValidator())
app.authmetadata.initialize(oauth2.MetadataEndpoint([oauthlib_server], claims={
"issuer": "https://xx",
"token_endpoint": "https://xx/token",
"revocation_endpoint": "https://xx/revoke",
"introspection_endpoint": "https://xx/tokeninfo"
}))
@app.get('/.well-known/oauth-authorization-server')
@app.authmetadata.create_metadata_response()
def metadata():
pass
if __name__ == "__main__":
app.run() # pragma: no cover
样例回答的输出:
$ curl -s http://localhost:8080/.well-known/oauth-authorization-server|jq .
{
"issuer": "https://xx",
"token_endpoint": "https://xx/token",
"revocation_endpoint": "https://xx/revoke",
"introspection_endpoint": "https://xx/tokeninfo",
"grant_types_supported": [
"password",
"refresh_token"
],
"token_endpoint_auth_methods_supported": [
"client_secret_post",
"client_secret_basic"
],
"revocation_endpoint_auth_methods_supported": [
"client_secret_post",
"client_secret_basic"
],
"introspection_endpoint_auth_methods_supported": [
"client_secret_post",
"client_secret_basic"
]
}
- class oauthlib.oauth2.MetadataEndpoint(endpoints, claims={}, raise_errors=True)[源代码]
OAuth2.0授权服务器元数据终结点。
此规范概括了由定义的元数据格式 OpenID Connect Discovery 1.0 in a way that is compatible with OpenID Connect Discovery while being applicable to a wider set of OAuth 2.0 use cases. This is intentionally parallel to the way that OAuth 2.0 Dynamic Client Registration Protocol [RFC7591 ]以与OpenID Connect动态客户端注册1.0兼容的方式概括了它定义的动态客户端注册机制。
- validate_metadata_server()[源代码]
授权服务器可以具有描述其配置的元数据。本规范使用以下授权服务器元数据值。更多详细信息,请参阅 RFC8414 section 2 :
- 发行人
REQUIRED
- authorization_endpoint
授权服务器的授权端点的URL [RFC6749#Authorization] 。这是必需的,除非不支持使用授权终结点的授权类型。
- token_endpoint
授权服务器的令牌端点的URL [RFC6749#Token] 。这是必需的,除非仅支持隐式授权类型。
- scopes_supported
推荐的。
- response_types_supported
必填。
- 其他可选字段:
Jwks_uri、注册端点、响应模式支持
- grant_types_supported
可选。包含此授权服务器支持的OAuth 2.0授权类型值列表的JSON数组。使用的数组值与“OAuth 2.0动态客户端注册协议”定义的“Grant_Types”参数使用的值相同。 [RFC7591] 。如果省略,则默认为“ ["authorization_code", "implicit"] “。”
token_endpoint_auth_methods_supported
token_endpoint_auth_signing_alg_values_supported
service_documentation
ui_locales_supported
op_policy_uri
op_tos_uri
revocation_endpoint
revocation_endpoint_auth_methods_supported
revocation_endpoint_auth_signing_alg_values_supported
introspection_endpoint
introspection_endpoint_auth_methods_supported
introspection_endpoint_auth_signing_alg_values_supported
code_challenge_methods_supported
还可以使用附加的授权服务器元数据参数。有些是由其他规范定义的,例如OpenID连接发现1.0 [OpenID.Discovery] 。