【问题标题】:Encryption request with access denied in pivotal config server关键配置服务器中拒绝访问的加密请求
【发布时间】:2018-08-15 16:41:42
【问题描述】:

当我运行下面的脚本时,我得到以下返回:

{"error": "access_denied", "error_description": "访问被拒绝"}

我该如何解决这个问题?

const request = require('request');
 
request({
  url: 'access_token_uri',
  method: 'POST',
  auth: {
    user: 'client_id',
    pass: 'client_secret'
  },
  form: {
    'grant_type': 'client_credentials'
  }
}, function(err, res) {
  var json = JSON.parse(res.body);
  encrypt(json.access_token, 'word');
});

function encrypt(token, word){
  request({
    url: 'uri/encrypt',
    method: 'POST',
    auth: {
      'bearer': token
    },
    body: word
  }, function(err, res) {
    console.log(res.body);
  });
}

【问题讨论】:

    标签: spring-cloud cloud-foundry pivotal-web-services


    【解决方案1】:

    从您的样本中很难分辨,但我认为您得到的令牌类型错误。对于/encrypt 端点,您需要一个基于密码的令牌。

    请参阅Get a Password Credentials Access Token 部分了解更多详情(我无法直接链接到该部分,您必须使用上一个链接向下滚动到该部分)。

    流程基本上是这样的:

    1. cf login
    2. cf oauth-token
    3. curl -H "Authorization: <oauth-token>" https://uri/encrypt -d 'Value to be encrypted'

    如果您想查看 cf cli 正在使用的 API,您可以 export CF_TRACE=true (Bash) 或 set CF_TRACE=true (Windows) 然后重复这些命令。这将转储 HTTP 请求/响应信息。

    【讨论】:

      猜你喜欢
      • 2016-04-19
      • 2018-05-19
      • 1970-01-01
      • 2014-12-21
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 2018-02-12
      相关资源
      最近更新 更多