2017-11-21 6 views
0

승인 요청 응답에서 인증 토큰을 저장하는 방법을 알아 내고 승인 된 요청을 작성하여 데이터베이스 정보를 가져올 수 있는지 확인하는 데 문제가 있습니다. 어떤 조언을 감사드립니다!인증 토큰 저장 및 사용

아래 코드에서 $ node index를 실행하면이 상태 403 응답을 얻습니다.

$ node index 
 
STATUS: 403 
 
STATUS: 200 
 
HEADERS: {"x-gs-rid":"notsureifthisinfoisconfidentialornot","content-type":"application/json;charset=utf-8","cache-control":"no-ca 
 
che, no-store, max-age=0, must-revalidate","pragma":"no-cache","expires":"0","strict-transport-security":"max-age=31536000 ; inc 
 
ludeSubDomains, max-age=15768000","x-xss-protection":"1; mode=block","x-frame-options":"DENY","x-content-type-options":"nosniff" 
 
,"connection":"close","set-cookie":["mesosphere_server_id=notsureifthisprivatetoo; path=/"]} 
 
BODY: {"country":"US","username":"myemailaddress","expiresAt":1511230469149,"X-GSAccessToken":"LotsofNumbersandLettersandPeriodsforTokenGoeshere"}

내 문제는 내가 할 수있는이 토큰 정식 저장하고 난 다음 요청을 할 수 있도록 데이터베이스를 config2.gamesparks.net하는 (즉, 지금 허가 것) 제대로 사용하려고하지만거야이다 ' 방법을 알아 내라.

var config  = require("./config.json"); 
 

 
var gameSparks = require("./GameSparks"); 
 

 
var https = require('https'); 
 
var options = { 
 
    host: 'auth.gamesparks.net', 
 
    path: '/restv2/auth/user', 
 
    headers: { 
 
     'Authorization':'Basic PRIVATEGSAUTHCODEHERE' 
 
    } 
 
}; 
 

 
var req = https.get(options, function(res) { 
 
    console.log('STATUS: ' + res.statusCode); 
 
    console.log('HEADERS: ' + JSON.stringify(res.headers)); 
 

 
    // Buffer the body entirely for processing as a whole. 
 
    var bodyChunks = []; 
 
    res.on('data', function(chunk) { 
 
    // You can process streamed parts here... 
 
    bodyChunks.push(chunk); 
 
    }).on('end', function() { 
 
    var body = Buffer.concat(bodyChunks); 
 
    console.log('BODY: ' + body); 
 
    // ...and/or process the entire body here. 
 
    }) 
 
}); 
 

 
req.on('error', function(e) { 
 
    console.log('ERROR: ' + e.message); 
 
}); 
 

 
var gsrequest = { 
 
    host: 'config2.gamesparks.net', 
 
    path: '/restv2/game/GSAPIKEYHEREcipm/endpoints/', 
 
    } 
 
}; 
 
var req = https.get(gsrequest, function(res) { 
 
    console.log('STATUS: ' + res.statusCode); 
 
});

+0

를 통해 액세스 할 수처럼 보이는 경우 은 당신의 PRIVATEGSAUTHCODE의 base64로 인코딩입니까? 사용자 : 아무것도 아닌 사용자로 인코딩 된 토큰을 기대합니까? – bryanmac

+0

네, 죄송합니다. 잘 모르겠다. 나는 여기서 눈이 멀었다. –

답변

1

JSON이 무엇인지 당신이 게시되어, 다음은 액세스 토큰이

body.X-GSAccessToken