dataservice.getToken().success(function (token) {
console.log(token);
rootRef.authWithCustomToken(token, function(error, authData) {
if (error) {
console.log('Login Failed!', error);
} else {
console.log('Authenticated successfully with payload:', authData);
}
});
}).error(function (error) {
console.log("Not able to get token data");
console.log(error);
});
我总是得到" INVALID_TOKEN:无法解析身份验证令牌。"但是,如果我从控制台日志中复制粘贴令牌并运行它,那么它可以正常工作。 token的dataType是string,expect也是String。
代码用于创建身份验证令牌:
public class FirebaseHelper {
public static final String SECRET = "<secret key>";
public static final String APP_URL = "<firebase url>";
public String getToken(final String Id) {
Map<String, Object> authPayload = new HashMap<String, Object>();
authPayload.put("uid", Id);
TokenGenerator tokenGenerator = new TokenGenerator(SECRET);
String token = tokenGenerator.createToken(authPayload);
return token;
}
}