나는 Postma 씨를 만들어보기 클릭 Authentication : Bearer JWT 생성을 돕기위한 사전 요청 스크립트. Firebase Auth를 사용하여 API를 테스트 할 때 많은 복사 붙여 넣기를 저장해야합니다. 게시 시간에 스크립트의 https://gist.github.com/moneal/af2d988a770c3957df11e3360af62635
복사 :
/**
* This script expects the global variables 'refresh_token' and 'firebase_api_key' to be set. 'firebase_api_key' can be found
* in the Firebase console under project settings then 'Web API Key'.
* 'refresh_token' as to be gathered from watching the network requests to https://securetoken.googleapis.com/v1/token from
* your Firebase app, look for the formdata values
*
* If all the data is found it makes a request to get a new token and sets a 'auth_jwt' environment variable and updates the
* global 'refresh_token'.
*
* Requests that need authentication should have a header with a key of 'Authentication' and value of '{{auth_jwt}}'
*
* Currently the nested assertions silently fail, I don't know why.
*/
pm.expect(pm.globals.has('refresh_token')).to.be.true;
pm.expect(pm.globals.has('firebase_api_key')).to.be.true;
var sdk = require('postman-collection'),
tokenRequest = new sdk.Request({
url: 'https://securetoken.googleapis.com/v1/token',
method: 'POST',
body: {
mode: 'urlencoded',
urlencoded: [{
type: 'text',
key: 'key',
value: pm.globals.get('firebase_api_key')
},
{
type: 'text',
key: 'grant_type',
value: 'refresh_token'
},
{
type: 'text',
key: 'refresh_token',
value: pm.globals.get('refresh_token')
},
]
}
});
pm.sendRequest(tokenRequest, function(err, response) {
pm.test('request for access token was ok', function() {
pm.expect(response).to.be.ok();
});
const json = response.json();
pm.expect(json).to.an('object');
pm.test('response json has needed properties', function() {
pm.expect(json).to.have.own.property('access_token');
pm.expect(json).to.have.own.property('token_type');
pm.expect(json).to.have.own.property('refresh_token');
const accessToken = json.access_token;
const tokenType = json.token_type;
const refreshToken = json.refresh_token;
pm.environment.set('auth_jwt', tokenType + ' ' + accessToken);
pm.globals.set('refresh_token', refreshToken);
});
});
당신은 적절한 범위와 액세스 토큰이 필요합니다은, 인증 코드는 OAuth는 2.0 액세스 토큰을 가져 오는 데 사용 단지 중간 자격증입니다. 일단 당신이 그것을 가지고 있다면,'Authorization : Bearer' –
권한이 거부 됨으로 헤더에 그것을 전달할 수 있습니다. 내가 사용하는 범위는 googleapis.com/auth/firebase입니다. 토큰이 작동하는지 어떻게 테스트 할 수 있습니까? 결함이 어디에 있는지 잘 모르겠 음 : 1. Google creds? 2. firebase auth/rules? 3. 우편 배달부로부터의 oauth? –
아래 게시물에 대한 내 업데이트 된 코멘트를 참조하십시오 :) –