The documentation you are viewing is for Dapr v1.11 which is an older version of Dapr. For up-to-date documentation, see the latest version.
OAuth2 client credentials
使用OAuth2客户端凭证中间件来保护HTTP端点的安全
	The OAuth2 client credentials HTTP middleware enables the OAuth2 Client Credentials flow on a Web API without modifying the application. 这种设计将认证/授权的关注点从应用中分离出来,因此应用操作者可以采用和配置认证/授权提供者,而不影响应用代码。
配置
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: oauth2clientcredentials
spec:
  type: middleware.http.oauth2clientcredentials
  version: v1
  metadata:
  - name: clientId
    value: "<your client ID>"
  - name: clientSecret
    value: "<your client secret>"
  - name: scopes
    value: "https://www.googleapis.com/auth/userinfo.email"
  - name: tokenURL
    value: "https://accounts.google.com/o/oauth2/token"
  - name: headerName
    value: "authorization"
元数据字段规范
| 字段 | 详情 | Example | 
|---|---|---|
| clientId | 您的应用程序的客户端ID,它是作为OAuth平台托管的凭证的一部分而创建的 | |
| clientSecret | 您的应用程序的客户密钥,它是作为OAuth平台托管的凭证的一部分而创建的。 | |
| scopes | 作用域的列表,通常用于应用程序中的授权,注意格式为空格分隔、大小写敏感的字符串 | "https://www.googleapis.com/auth/userinfo.email" | 
| tokenURL | 客户端通过出示其访问许可或刷新令牌来获取access token的端点 | "https://accounts.google.com/o/oauth2/token" | 
| headerName | 转发到您的应用程序的授权头名称 | "authorization" | 
| endpointParamsQuery | 指定令牌端点请求的额外参数 | true | 
| authStyle | 可选择指定端点希望 客户端ID & 客户端密钥 的发送方式。 请参阅下面可能的值表 | 0 | 
authStyle 的可能值
| 值 | 含义 | 
|---|---|
| 1 | 将POST body中的"client_id"和"client_secret"作为 application/x-www-form-urlencoded 参数发送。 | 
| 2 | 使用 HTTP Basic授权发送"client_id" 和 “client_secret” 这是 OAuth2 RFC 6749 节 2.31中描述的可选风格。 | 
| 0 | 是指通过两种方式的尝试,自动检测提供者想要的认证方式,并将成功的方式缓存起来,以备将来使用。 | 
Dapr配置
To be applied, the middleware must be referenced in a configuration. See middleware pipelines.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  httpPipeline:
    handlers:
    - name: oauth2clientcredentials
      type: middleware.http.oauth2clientcredentials
相关链接
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.