繁体   English   中英

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

[英]Auth0: Error when JSON serializing the result of the extension point

我正在通过服务器代理向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();
}

原来,我的一个钩子正在返回一些奇怪的数据或某些东西,从而导致了错误。 挂钩已删除,问题已解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM