【问题标题】:Coinbase Connect (OAuth2) "The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed."Coinbase Connect (OAuth2) “请求缺少必需的参数,包含不受支持的参数值,或者格式错误。”
【发布时间】:2016-08-30 23:10:29
【问题描述】:

亲爱的stackoverflower,

我打算用 Coinbase 集成构建一个 Electron 应用程序。

首先我要让服务器 (NodeJS) 与 OAuth2 一起工作。

一切都很好,但是当我想使用指示的发布请求将code 更改为access token 时,它给了我以下错误:

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

我已经将 https://localhost:3000/auth/coinbase/callbackhttps://localhost:3000/profile 添加到有效的 API URI 中。

几个小时后我还是没能成功。

我的服务器是这样的:

var express = require('express');
var app = express();
var fs = require('fs')
var https = require('https');
var coinbase = require('coinbase')
var request = require('request');

var options = {
    key: fs.readFileSync('./ssl/coinbase.dev.key'),
    cert: fs.readFileSync('./ssl/coinbase.dev.crt'),
};

var client_id = 'gues it'
var client_secret = 'gues it'

app.use(express.static('static'));

app.get('/login/coinbase', function(req, res) {
    res.redirect('https://www.coinbase.com/oauth/authorize?response_type=code&redirect_uri=https://localhost:3000/auth/coinbase/callback&client_id=' + client_id + '&scope=wallet:user:read,wallet:accounts:read')
})

app.get('/auth/coinbase/callback', function(req, res) {
    var data = {
        client_id: client_id,
        client_secret: client_secret,
        grant_type: 'authorization_code',
        code: req.query.code,
        redirect_uri: 'https://localhost:3000/profile'
    }

    request.post(
        'https://api.coinbase.com/oauth/token', data, function (error, response, body) {
            console.log(body)
            res.send(body)
        }
    );
})

app.get('/', function(req, res) {
    res.send('home')
})

app.get('/profile', function(req, res) {
    res.send('profile')
})

var server = https.createServer(options, app);

server.listen(3000)

提前致谢,

西奥

[编辑] 我联系了 Coinbase 开发人员,他们很惊讶在 Coinbase 的 OAuth 上没有 NodeJS 示例,因此他们将其添加到他们的路线图中。

【问题讨论】:

    标签: node.js express coinbase-api


    【解决方案1】:

    这很可能是由以下原因之一引起的:

    1. 您的应用程序设置中没有将 'http://127.0.0.1:3000/profile' 列为有效的重定向 API。
    2. 您正在重用已交换令牌的授权代码。
    3. 本栏目this page

    OAuth2 重定向 URI

    为了增加安全性,所有 redirect_uris 必须使用 SSL(即以 https://)。没有 SSL 的 URI 只能用于开发和 正在测试中,不会在生产中得到支持。

    联系 api@coinbase.com 以解决问题。

    【讨论】:

    • 我确实将https://localhost:3000/auth/coinbase/callbackhttps://localhost:3000/profile 添加到了有效的重定向URI。并使用 ssl 从 https 为我的本地开发服务器提供服务。但我仍然遇到同样的错误。我将编辑我的问题中的代码。
    猜你喜欢
    • 1970-01-01
    • 2018-06-04
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多