我正在制作一个应该使用 oAuth 对来自暴雪服务器的玩家进行身份验证的应用程序,我想访问他们的角色信息……但我不知道如何请求 secret_token。我想我的发布请求错误如下是我正在使用的代码
app.post('/', function(req, res) {
var code = req.body.code; //this is the code i get ounce the player is redirected back to my redirect_uri
var redirectUri = "https://localhost:3000/oauth_callback.html";
var scope = "wow.profile";
var key = "they client_id i was given";
var secret = "they secret I was given";
var grantType = "authorization_code";
var tokenUri = "https://us.battle.net/oauth/token";
var uriBody = "?client_id=" + key + "&client_secret=" + secret + "&grant_type=authorization_code&code=" + code + "&redirect_uri=" + redirectUri + "&scope=" + scope;
request({
url: tokenUri, //URL to hit
method: 'POST',
headers: {
'Content-Type': "application/x-www-form-urlencoded",
},
body: uriBody //Set the body as a string
}, function(error, response, body){
if(error) {
console.log(error);
} else {
console.log(response.statusCode, body);
}
});
所以基本上我正在获取代码向我的服务器发出发布请求,然后触发对暴雪服务器的发布请求,试图将我的代码交换为访问令牌。
我得到的错误是:
401 '{"error":"unauthorized","error_description":"An Authentication object was not found in the SecurityContext"}'
我正在使用Node.js
&request.js
发布帖子,我猜我没有发出正确的请求发布请求?