ios - Coinbase API 无效请求(oauth token )

标签 ios swift oauth oauth-2.0 coinbase-api

我正在尝试使用Coinbase API进行oauth,但不断收到无效的请求响应“请求缺少必需的参数,包含不受支持的参数值,或者格式错误.”

按照他们的指南 https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating ,我能够:

  1. 成功重定向用户以请求 Coinbase 访问权限

获取https://www.coinbase.com/oauth/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URL&state=SECURE_RANDOM&scope=wallet:accounts:read

  1. 成功将 Coinbase 重定向回您的网站

获取https://example.com/oauth/callback?code=4c666b5c0c0d9d3140f2e0776cbe245f3143011d82b7a2c2a590cc7e20b79ae8&state=134ef5504a94 app://oauth-coins?code=4c666b5c0c0d9d3140f2e0776cbe245f3143011d82b7a2c2a590cc7e20b79ae8

  • 未能成功地将代码交换为访问 token 发布https://api.coinbase.com/oauth/token

    let url = URL(string: "https://api.coinbase.com/oauth/token")! //
    var request = URLRequest(url: url)
    request.setValue("authorization_code", forHTTPHeaderField: "grant_type")
    request.setValue("\(self.code)", forHTTPHeaderField: "code")
    request.setValue("clientid1234", forHTTPHeaderField: "client_id")
    request.setValue("clientsecret1234", forHTTPHeaderField: "client_secret")
    request.setValue("app://oauth-coins", forHTTPHeaderField: "redirect_uri")
    
  • 因为我在 json 中收到错误返回:

    {
        error = "invalid_request";
        "error_description" = "The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.";
    }
    

    更新(已解决):

    我不需要为所有参数设置setValue,而是将它们作为request.httpBody发布

    最佳答案

    我不需要为所有参数设置setValue,而是将它们作为request.httpBody发布

    关于ios - Coinbase API 无效请求(oauth token ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56139421/

    相关文章:

    c# - 谁能解释一下 OAuth?

    api - Grails Rest API 与适用于移动应用程序的 OAuth

    ios - 如何防止物理体改变 Sprite Kit 中的 x 位置

    ios - 带有辅助类的 xib 文件按钮不起作用

    swift - StackView 已停止在 Xcode 10/iOS 12 中获取高度

    ios - UITableViewCell 阴影

    ios - 如何在 iPad Air2 iOS9.2 的某些 ViewController 上强制屏幕方向?

    ios - 为什么 UIViewController 的 'view' 属性在 Swift 中不是可选的?

    swift - 我如何用具有多个字符的字符串拆分字符

    python - 如何检查用户是否是 App Engine 中其 Google Apps 域的管理员?