The documentation you are viewing is for Dapr v1.7 which is an older version of Dapr. For up-to-date documentation, see the latest version.

OAuth2

使用OAuth2中间件来保护HTTP端点的安全

The OAuth2 HTTP middleware enables the OAuth2 Authorization Code flow on a Web API without modifying the application. 这种设计将认证/授权的关注点从应用中分离出来,因此应用操作者可以采用和配置认证/授权提供者,而不影响应用代码。

配置

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: oauth2
spec:
  type: middleware.http.oauth2
  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: authURL
    value: "https://accounts.google.com/o/oauth2/v2/auth"
  - name: tokenURL
    value: "https://accounts.google.com/o/oauth2/token"
  - name: redirectURL
    value: "http://dummy.com"
  - name: authHeaderName
    value: "authorization"
  - name: forceHTTPS
    value: "false"

元数据字段规范

字段 详情 Example
clientId 您的应用程序的客户端ID,它是作为OAuth平台托管的凭证的一部分而创建的
clientSecret 您的应用程序的客户密钥,它是作为OAuth平台托管的凭证的一部分而创建的。
scopes 作用域的列表,通常用于应用程序中的授权,注意格式为空格分隔、大小写敏感的字符串 "https://www.googleapis.com/auth/userinfo.email"
authURL OAuth2 授权服务器的端点 "https://accounts.google.com/o/oauth2/v2/auth"
tokenURL 客户端通过出示其访问许可或刷新令牌来获取access token的端点 "https://accounts.google.com/o/oauth2/token"
redirectURL 用户认证后,授权服务器应重定向到的Web应用程序的URL "https://myapp.com"
authHeaderName 转发到您的应用程序的授权头名称 "authorization"
forceHTTPS 如果为true,强制使用TLS/SSL "true","false"

Dapr配置

To be applied, the middleware must be referenced in configuration. See middleware pipelines.

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  httpPipeline:
    handlers:
    - name: oauth2
      type: middleware.http.oauth2

相关链接