【问题标题】:Unable to get token from Thinktecture Authorization Server无法从 Thinktecture 授权服务器获取令牌
【发布时间】:2015-05-04 18:00:07
【问题描述】:

我无法从 Thinktecture 授权服务器获取访问令牌。成功获得授权代码后,我尝试向令牌端点发出 POST 请求,但始终收到带有此响应的 400 Bad Request: 消息:“{“错误”:“invalid_client”}”

我的要求是: 发布到https://host/authz/users/oauth/token 请求正文: {"code":"grant_code_received_from_previous_request","client_id":"myclient","grant_type":"authorization_code","client_secret":"mysecret"}

我的客户端已在授权服务器中正确设置。我的客户 ID 和密码正确;它们与我在上一个请求(/users/oauth/authorize)中用于授权代码的值相同。

对这个“invalid_client”问题有什么想法吗?响应中除了“invalid_client”之外没有其他信息。

【问题讨论】:

    标签: oauth oauth-2.0 thinktecture-ident-server thinktecture-ident-model thinktecture


    【解决方案1】:

    您需要使用 http 基本身份验证发送客户端凭据,而不是在正文中发布 Id 和 secret。

    【讨论】:

    • 嗨,多米尼克,我在标题中添加了基本的 authz,我也在使用 Advanced rest 客户端扩展。但仍然得到 invalid_client 。任何想法
    【解决方案2】:

    我遵循了@leastprivilege 的建议并做到了:

    // set up the base64-encoded credentials
    let clientId = "myclientid"
    let clientSecret = "myclientsecret"
    
    let loginString = NSString(format: "%@:%@", clientId, clientSecret)
    let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)!
    let base64LoginString = loginData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(0))
    

    然后像这样创建请求实例:

    var request = NSMutableURLRequest(URL: myUrl!)
    request.HTTPMethod = "POST"
    
    // Only these four are required based on the documentation.        
    let postString = "grant_type=authorization_code&code=\(code)&redirect_uri=app:/your.redirect.uri"
    
    request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
    
    request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
    

    希望对你有帮助!

    【讨论】:

      【解决方案3】:

      您可以获得有关日志文件的更多信息。 看一下,可以在 Identity Server 的 web.config 中查看日志记录选项:

       <system.diagnostics>
      <!-- simple system.diagnostics logger -->
      <trace autoflush="true" indentsize="4">
        <listeners>
          <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="Trace.log" />
          <remove name="Default" />
        </listeners>
      </trace>
      
      <!-- can be used with TraceSource logger -->
      <!--<sources>
        <source name="Thinktecture.IdentityServer"
                switchValue="Information, ActivityTracing">
          <listeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData= "trace.svclog" />
          </listeners>
        </source>
      </sources>-->
      

      有关登录的更多信息: http://identityserver.github.io/Documentation/docs/configuration/logging.html

      【讨论】:

        猜你喜欢
        • 2014-02-08
        • 2019-12-04
        • 1970-01-01
        • 2019-06-19
        • 1970-01-01
        • 1970-01-01
        • 2016-07-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多