Oauth 2.0 “如何改变”;范围“;使用Auth2.0(连接、招摇)

Oauth 2.0 “如何改变”;范围“;使用Auth2.0(连接、招摇),oauth-2.0,scope,swagger,access-token,connexion,Oauth 2.0,Scope,Swagger,Access Token,Connexion,我想通过OAuth2.0理解这个身份验证示例,但我仍停留在scopes部分: 在app.yaml中,我们将“uid”定义为应用程序的必要范围: /secret: get: summary: Return secret string operationId: app.get_secret responses: 200: description: secret response schema:

我想通过OAuth2.0理解这个身份验证示例,但我仍停留在scopes部分:

在app.yaml中,我们将“uid”定义为应用程序的必要范围:

  /secret:
    get:
      summary: Return secret string
      operationId: app.get_secret
      responses:
        200:
          description: secret response
          schema:
            type: string
      security:
        # enable authentication and require the "uid" scope for this endpoint
        - oauth2: ['uid']
在app.yaml的安全定义中,“uid”再次出现在scopes部分,并且作为x-tokenInfoUrl(我需要)的答案是必需的

在我们的tokeninfo模拟应用程序(mock_tokeninfo.yaml)中,我们看到返回了“uid”,并且作用域实际上是我们想要的“uid”

return {'uid': uid, 'scope': ['uid']}
最后,在mock_tokeninfo.yaml中,我们在响应中有“uid”和作用域:

      responses:
        200:
          description: Token info object
          schema:
            type: object
            properties:
              uid:
                type: string
              scope:
                type: array
                items:
                  type: string
所以我现在理解的是,当app.py在端口8080上启动时,我用“/secret”调用端口8080上的localhost,安全部分检查所需内容并看到“uid”。它遵循localhost:7979上的x-tokenInfoUrl,我们在那里启动了mock_tokeninfo应用程序,它返回给我们一个“uid”和作用域“uid”

现在我的问题是:我现在有一个自己的身份提供者,希望从那里访问userinfo。我将x-tokenInfoUrl更改为如下内容:
https:////userinfo
当我这样做curl时:
curl-H'Authorization:Bearer
但这也没什么帮助

我检查了一下,如果报头确实被重定向了,并且确实被重定向了

我发现了这样一句话:“然而,为了使这一点明确化,在这种情况下,您应该分配uid伪权限。它是用户id,并且始终作为OAuth2默认作用域可用”,但同样-如果这是一个伪权限,我如何做一个普通作用域

在我找到的每个示例中(pet读/写示例是最常见的一个),范围变量似乎都有自定义名称。。。()


这里是“安全性”部分的文档,可能我误解了什么:

所以最终找到了解决方案。问题是文档没有更新。这是指向文档的链接:

它说:

令牌信息响应的子属性将在用户参数中传递给处理函数

进一步调查发现connexion包的此提交消息:

用该短语更新不充分的描述:

令牌信息响应将在
Token\u Info
参数中传递给处理程序 功能。令牌信息响应的
sub
属性将在
用户中传递
处理程序函数的参数

因此,从这里输入有关“无作用域”的信息:

结合提交消息中的信息,我们可以更改示例,如下所示:

app.yaml:

security:
    # enable authentication and require the "uid" scope for this endpoint
    - oauth2: []

securityDefinitions:
  oauth2:
    type: oauth2
    x-tokenInfoUrl: https://<my_idp>/<some_paths>/userinfo
    scopes: {}
通过这种方式,我获得了身份提供者传递的所有信息

谢谢大家和我一起思考:)希望,你会觉得这很有用。

只是想澄清一下:对于“我自己的身份提供者”,我的意思是“暹罗-官方身份提供者”。
{"mail":"<my_email>",
"name":"<my_name>"}
403 - forbidden
provided token does not have the required scope
Content-Type: application/problem+json
app.yaml:

security:
    # enable authentication and require the "uid" scope for this endpoint
    - oauth2: []

securityDefinitions:
  oauth2:
    type: oauth2
    x-tokenInfoUrl: https://<my_idp>/<some_paths>/userinfo
    scopes: {}
app.py:

get_secret(token_info):
    return token_info