2016-07-29 5 views
4

나는 postbase를 사용하여 firebase에 대한 REST API 호출을 시도합니다. 내 보안 규칙이 권한이없는 사용자를 포함하여 모든 사용자를 허용하는 것이면 firebase에서 읽을 수있었습니다. 나는 '오류'를 얻을postman을 사용하여 firebase REST API에 액세스

{"rules":{".read": "auth != null", ".write": "auth != null"}} 

: 나는이 규칙을 사용하면

하지만 우편 배달부에서 '권한이 거부'. Google의 웹 oauth2.0 클라이언트에 대한 요청 토큰을 수행하고 authorization_code 토큰을 다시 가져 왔습니다.

URL과 헤더에서 토큰을 사용하려고 시도했지만 GET & POST 요청으로 시도했지만 여전히 거부됩니다.

도와주세요.

https://your-database-url/users.json?auth=YOUR_AUTH_KEY

곳이

https://your-database-url/users.json?auth=YOUR_AUTH_KEY 

Respone 같은 사전에 감사

+0

당신은 적절한 범위와 액세스 토큰이 필요합니다은, 인증 코드는 OAuth는 2.0 액세스 토큰을 가져 오는 데 사용 단지 중간 자격증입니다. 일단 당신이 그것을 가지고 있다면,'Authorization : Bearer ' –

+0

권한이 거부 됨으로 헤더에 그것을 전달할 수 있습니다. 내가 사용하는 범위는 googleapis.com/auth/firebase입니다. 토큰이 작동하는지 어떻게 테스트 할 수 있습니까? 결함이 어디에 있는지 잘 모르겠 음 : 1. Google creds? 2. firebase auth/rules? 3. 우편 배달부로부터의 oauth? –

+0

아래 게시물에 대한 내 업데이트 된 코멘트를 참조하십시오 :) –

답변

3

시도 뭔가는이 같은 일을 저를 위해 사용자 노드

+0

여전히 권한이 거부되었습니다. 내가 사용하는 범위는 입니다. https://www.googleapis.com/auth/firebase –

+0

https://project-5345143141106430789.firebaseio.com/users.json?access_token = ya29.Ci8wAzAqJp346BXPzy0NgeHCqZeF7w82FS_zaVPa902ncwtMpC4V-c8X9SFcQIujDg –

+1

교정 : 그래서 나는 auth 대신에 access_token 매개 변수를 사용하고있었습니다. 그게 바로 퍼미션이 거부 된 이유입니다. AUTH로 변경 한 후 오류가 발생했습니다 : 반환 된 access_token을 사용할 때 "인증 토큰을 파싱하지 못했습니다." firebase 문서 당 문서는 인증 된 토큰이나 firebase의 앱 비밀 중 하나를 사용하여 액세스 할 수 있습니다. 후자를 AUTH 값으로 사용하여 데이터를 가져 왔습니다. 하지만 auth'ed 토큰을 사용하면 여전히 오류가 발생 함 –

2

의 JSON입니다 이 AUTH_KEY를 가져올 수 있습니까?

당신은 답은 위의 나를 위해 작동하지 않았다 당신의 Project Settings -> Database -> Secret Key

+0

프로젝트 설정 -> 데이터베이스 -> 비밀 키? 해당 경로가 없습니다 – CodyBugstein

+2

비밀 번호는 프로젝트 설정 -> 서비스 계정 (탭) -> 데이터베이스 비밀 번호 을 클릭하여 firebase 콘솔에서 액세스 할 수 있습니다. 그러면 비밀 키 위로 마우스를 이동하면 '표시'버튼이 표시됩니다 . 이것을 클릭하면 볼 수 있습니다. 또한 왼쪽 메뉴의 데이터베이스 항목을 클릭하여 콘솔에서 데이터베이스 URL을 찾을 수 있습니다. – omarjebari

+1

Firebase 콘솔의 데이터베이스 -> 규칙에서 시뮬레이터를 사용해보십시오. 유효한 인증 요청을 작성하여 우편 배달부에 복사 할 수 있습니다. – omarjebari

8

에서이 키를 얻을.

나를 위해 일을

프로젝트 설정 (왼쪽 상단 기어)로가는 무슨 짓을 ->데이터베이스 비밀 (왼쪽 메뉴) - -> 스크롤>서비스 (맨 오른쪽 탭) 계정 아래, bulltets 위에 마우스와 은 즉, 인증 키와

사용이, .../mycollection.json?auth=HERE

+0

.json은 나머지 API에 필수입니다. –

1

나는 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); 

    }); 

}); 
관련 문제