使用 Auth0 和 Aurelia 检索 Facebook 用户好友列表
Retrieving a Facebook User Friends List using Auth0 and Aurelia
我在我的 Aurelia 单页应用程序中使用 Auth0 进行用户身份验证。我可以在 app.js
中使用下面的代码成功登录和注销
login() {
this.lock.show();
}
并且在构造函数中:
this.lock.on('authenticated', (authResult) => {
self.lock.getProfile(authResult.idToken, (error, profile) => {
if (error) {
// Handle error
console.log(error);
return;
}
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem('profile', JSON.stringify(profile));
self.isAuthenticated = true;
self.lock.hide();
});
}
我现在想调用 Facebook Graph API 并检索已登录用户的好友列表。我已经设置了授予此功能的应用程序访问权限的权限。我正在尝试使用此获取模块获取朋友列表,例如:
this.http.fetch('https://graph.facebook.com/v2.5/{user-id}/friends', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + authResult.idToken
}
})
.then(response => response.json())
.then(friends => this.friends = friends);
但是我收到一个错误 "An access token is required to request this resource"。我不知道我这样做是否正确。我已经阅读了文档,但我被卡住了。我将非常感谢提供的任何帮助。谢谢大家!
您需要使用 Facebook 颁发的访问令牌调用 Facebook API,而不是作为身份验证过程的一部分颁发的 Auth0 id_token
。
Identity Provider (in this case Facebook) access tokens can be obtained after the user has authenticated with the IdP by making an HTTP GET call to the /api/v2/user/{user-id}
endpoint containing an Auth0 API token generated with read:user_idp_tokens
scope.
有关此内容的更多信息,请参阅 Identity Provider Access Tokens in the existing documentation. That page also links to a ste-by-step tutorial on how to Call an Identity Provider API 上的主题。
我在我的 Aurelia 单页应用程序中使用 Auth0 进行用户身份验证。我可以在 app.js
中使用下面的代码成功登录和注销login() {
this.lock.show();
}
并且在构造函数中:
this.lock.on('authenticated', (authResult) => {
self.lock.getProfile(authResult.idToken, (error, profile) => {
if (error) {
// Handle error
console.log(error);
return;
}
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem('profile', JSON.stringify(profile));
self.isAuthenticated = true;
self.lock.hide();
});
}
我现在想调用 Facebook Graph API 并检索已登录用户的好友列表。我已经设置了授予此功能的应用程序访问权限的权限。我正在尝试使用此获取模块获取朋友列表,例如:
this.http.fetch('https://graph.facebook.com/v2.5/{user-id}/friends', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + authResult.idToken
}
})
.then(response => response.json())
.then(friends => this.friends = friends);
但是我收到一个错误 "An access token is required to request this resource"。我不知道我这样做是否正确。我已经阅读了文档,但我被卡住了。我将非常感谢提供的任何帮助。谢谢大家!
您需要使用 Facebook 颁发的访问令牌调用 Facebook API,而不是作为身份验证过程的一部分颁发的 Auth0 id_token
。
Identity Provider (in this case Facebook) access tokens can be obtained after the user has authenticated with the IdP by making an HTTP GET call to the
/api/v2/user/{user-id}
endpoint containing an Auth0 API token generated withread:user_idp_tokens
scope.
有关此内容的更多信息,请参阅 Identity Provider Access Tokens in the existing documentation. That page also links to a ste-by-step tutorial on how to Call an Identity Provider API 上的主题。