如何使用 Firebase 身份验证令牌使用 js 列出用户博客
How to use Firebase authentication token to list user blogs using js
我正在尝试检索经过身份验证的用户博客(授权范围):
var token = await firebase.auth().currentUser.getIdToken();
fetch('https://www.googleapis.com/blogger/v3/users/self/blogs', {
"headers": {
"Authorization": "Bearer " + token
},
"method" : "GET",
"muteHttpExceptions": true
}).then( r => console.log(r) );
但我收到错误:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Invalid Credentials",
"domain": "global",
"reason": "authError",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
你能告诉我在不使用后端的情况下我缺少什么吗?
Firebase 身份验证 ID 令牌是 JWT。 Blogger 需要 OAuth 2 令牌,而 Firebase 身份验证令牌不是。
虽然可以在 Firebase 中创建基于 OAuth 令牌的 ID 令牌,但反之则不行。您必须改为使用 OAuth 2 提供商登录用户,并将 that 令牌传递给 blogger。
我正在尝试检索经过身份验证的用户博客(授权范围):
var token = await firebase.auth().currentUser.getIdToken();
fetch('https://www.googleapis.com/blogger/v3/users/self/blogs', {
"headers": {
"Authorization": "Bearer " + token
},
"method" : "GET",
"muteHttpExceptions": true
}).then( r => console.log(r) );
但我收到错误:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Invalid Credentials",
"domain": "global",
"reason": "authError",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
你能告诉我在不使用后端的情况下我缺少什么吗?
Firebase 身份验证 ID 令牌是 JWT。 Blogger 需要 OAuth 2 令牌,而 Firebase 身份验证令牌不是。
虽然可以在 Firebase 中创建基于 OAuth 令牌的 ID 令牌,但反之则不行。您必须改为使用 OAuth 2 提供商登录用户,并将 that 令牌传递给 blogger。