Auth0:JSON序列化扩展点的结果时出错

时间:2018-04-18 18:40:17

标签: node.js proxy jwt auth0

我正在通过服务器代理向Auth0发送一个令牌请求,它工作得非常好。但是,今天相同的代码只会返回:

{"error":"server_error","error_description":"Error when JSON serializing the result of the extension point"}

我在这里缺少什么?这感觉特别愚蠢,因为上周没有问题,而且代码自那以后没有改变。

提前感谢任何阅读/评论的人。

原始要求: {baseURL}/{API PATH}/post?path=https://apropostenantname.auth0.com/oauth/token

体: {"grant_type":"client_credentials","client_id":"XXX","client_secret":"XXX","audience":"XXX"}

选项,在发送到Auth0之前:

{ host: 'apropostenantname.auth0.com',
   path: '/oauth/token',
   port: undefined,
   method: 'POST',
   headers: 
    { 'Content-Type': 'application/json',
      'Content-Length': 200} }

这是代理控制器:

"use strict";
var rethinkdb = require('rethinkdb');
var async = require('async');
const deepmerge = require('deepmerge');

var https = require('https');
var util = require('util');
var querystring = require('querystring');


exports.proxyPost =  (req,res)=>{
    let req_url = req.query.path;
    let body = JSON.stringify(req.body);
    let auth = req.header('Authorization') ? req.header('Authorization') : null;
    // no auth headers sent with this particular request.
    let contenttype =  req.header('Content-Type') ? req.header('Content-Type')  : 'application/json';
    var headers = {
        'Content-Type': contenttype,
        'Content-Length': body.length
    };

    if(auth != null){
        headers['Authorization'] = auth;
    }
    var match = req_url.match(/^(?:(https?:)?\/\/)?(([^\/?]+?)(?::(\d{0,5})(?=[\/?]|$))?)([\/?][\S\s]*|$)/i);
    //                              ^^^^^^^          ^^^^^^^^      ^^^^^^^                ^^^^^^^^^^^^
    //                            1:protocol       3:hostname     4:port                 5:path + query string
    //                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    //                                            2:host
    let protocol = match[1];
    let host = match[3];
    let port = match[4];
    let path = match[5];
    var options = {
        host: host,
        path: path,
        port:port,
        method: 'POST',
        headers: headers
    };
    console.log(options);
    var _req = https.request(options, function(_res) {
        _res.setEncoding('utf-8');
        let header_keys = Object.keys(_res.headers);
        for(let header of header_keys){
            res.setHeader(header, _res.headers[header]);
        }

        var responseString = '';
        _res.on('data', function(data) {
            responseString += data;
        });

        _res.on('end', function() {
            var responseObject = responseString ? JSON.parse(responseString) : '';
            res.send(responseObject);
        });
    });

    _req.write(body);
    // console.log(_req);
    _req.end();
}

1 个答案:

答案 0 :(得分:0)

事实证明我的一个钩子正在返回一些奇怪的数据或其他东西,这导致了错误。钩子被删除,问题解决了。