【问题标题】:How to get AccessToken如何获取访问令牌
【发布时间】:2022-01-07 16:30:14
【问题描述】:

我正在构建一个客户端,需要帮助来获取访问令牌。

想知道在 grant_type 中需要传递什么?客户断言? 从哪里获得这些值?因为在提供 AccessToken 的身份验证中需要这些值

POST /token HTTP/1.1 主持人::443 时间戳:1212669235 日期:2016 年 5 月 12 日星期五 17:21:16 GMT+0000 内容类型:application/x-www-form-urlencoded

grant_type=client_credentials&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&scope=profile-search&client_assertion=

HTTP/1.1 200 正常 内容类型:application/json;charset=UTF-8 内容长度:653 日期:格林威治标准时间 2019 年 10 月 29 日星期二 14:13:29 { "access_token" : "KjdsjEeRFwksjqefindikHAfDKV...", “token_type”:“持票人” “expires_in”:3600 “范围”:“配置文件搜索” }

【问题讨论】:

    标签: c# oauth-2.0 jwt


    【解决方案1】:

    要获取客户端凭据类型 OAuth 机制的令牌,需要以下参数:

    grant_type = client credentials
    Access Token URL = <the Auth server URL token end point>
    ClientId = <the Id from the auth server where app is registered>
    ClientSecret = <value for the secret set>
    Scope = <scope as defined for the application>
    

    附上来自 Postman 的示例应用程序的屏幕截图,以生成此授权类型的令牌。

    更多细节可以参考:https://www.oauth.com/oauth2-servers/access-tokens/client-credentials/

    Azure AD 设置的示例在这里:https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow

    【讨论】:

    • 感谢您的回复。但是,如果您在我提出的问题中看到,目标系统需要请求参数 client_assertion,即(JWS)。此外,目标系统提到他们不使用 Basic Auth 进行身份验证......他们进行 Bearer Authorization。
    • client_assertion 是 JWT 令牌,将使用您将提供的证书进行签名。您可以使用 Postman (documenter.getpostman.com/view/4630964/S1Lr3qtg) 或在线工具 (oauth.tools/collection/1638334128507-uDb) 以编程方式 (stormpath.com/blog/jwt-java-create-verify) 生成令牌。
    • 因为 client_assertion 是 JWT 令牌,将使用 cert 进行签名.....那么我的问题是如何从 Header 和 Payload 中获取值?由于这些 Header 和 Payload 组合是 JWT Token,需要作为输入参数传递以获取 Access Token 作为响应。这些值会动态变化
    猜你喜欢
    • 2012-02-15
    • 2018-10-11
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    相关资源
    最近更新 更多