我在Firebase 2中使用JWT进行了身份验证,但是自从迁移到Firebase 3后,我无法使用它。我认为这是由于令牌生成器库没有生成正确的JWT。任何人都可以看到问题在哪里吗?
JS代码:
// set Firebase from config
var config = {
apiKey: 'api_key',
authDomain: 'domain',
databaseURL: 'database_url',
storageBucket: 'storage_bucket',
};
firebase.initializeApp(config);
firebase.database.enableLogging(true);
var ref = firebase.database();
firebase.auth().signInWithCustomToken(jwt).catch(function(error) {
if (error) {
console.log("Authentication Failed!", error.code + ' ' + error.message);
} else {
...
}
PHP代码:
使用:firebase-php,php-jwt和token-generator
$now_seconds = time();
$payload = array(
'iss' => FIREBASE_SERVICE_ACCOUNT_EMAIL,
'sub' => FIREBASE_SERVICE_ACCOUNT_EMAIL,
'aud' => 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
'iat' => $now_seconds,
'exp' => $now_seconds+(60*60), // Maximum expiration time is one hour
'uid' => $uid
);
return JWT::encode($payload, FIREBASE_PRIVATE_KEY, 'HS256');
调试:
p:0: Browser went online.
firebase.js:354 p:0: Auth token refreshed
firebase.js:354 p:0: Making a connection attempt
firebase.js:354 getToken() completed. Creating connection.
firebase.js:354 c:0:0: Connection created
firebase.js:354 c:0:0:0 Websocket connecting to wss://my-app.firebaseio.com/.ws?v=5&ns=my-app
my-page:1041 POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=my-key 400 ()
firebase.js:354 c:0:0:0 Websocket connected.
firebase.js:354 c:0:0: Realtime connection established.
firebase.js:354 p:0: connection ready
firebase.js:354 p:0: reportStats {"c":{"sdk.js.3-0-0":1}}
firebase.js:354 p:0: {"r":1,"a":"s","b":{"c":{"sdk.js.3-0-0":1}}}
firebase.js:354 p:0: from server: {"r":1,"b":{"s":"ok","d":""}}
about:blank:1 Refused to display 'https://accounts.google.com/ServiceLogin?service=cloudconsole&osid=1&passiv…=http%3A%2F%2Flocal.domain.com%3ALOCALPORTNUMBER&pfname=&rpctoken=RPCTOKENNUMBER' in a frame because it set 'X-Frame-Options' to 'DENY'.
firebase.js:354 c:0:0: sending ping on primary.
firebase.js:354 c:0:0: got pong on primary.
firebase.js:354 c:0:0: Primary connection is healthy.