在 meteor oauth 中访问 github 用户数据
accessing github user data in meteor oauth
我正在尝试使用 github 对用户进行身份验证,然后将他们的 avatar_url
传递给客户端。简化的结构如下所示。
server/
publications.js
client/
users/
login.js
main.js
在我的 client/users/login.js
文件中,我尝试获取对包含头像 url
的用户对象的权限
Accounts.ui.config({
requestPermissions: {
github: ['user']
}
});
然后在我的 server/publications.js
中,我尝试发布 the data related to the avatar url。
Meteor.publish('userData', function() {
if(this.userId) {
return Meteor.users.find(
{ _id: this.userId }, {
fields: {
'services.github.id': 1,
'services.github.user.avatar_url': 1
}
})
} else {
this.ready();
}
});
然而,当我得到我的用户对象时,我从来没有得到与 github 用户相关的数据。如何使用 OAuth 访问用户?
请查看此示例代码,您是否在 CreateUser 上捕获了 Github 配置文件数据?
编辑:这是服务器端代码,例如server/accounts.js
Accounts.onCreateUser(function (options, user) {
var accessToken = user.services.github.accessToken,
result,
profile;
result = Meteor.http.get("https://api.github.com/user", {
params: {
access_token: accessToken
}
});
if (result.error)
throw result.error;
profile = _.pick(result.data,
"login",
"name",
"avatar_url",
"url",
"company",
"blog",
"location",
"email",
"bio",
"html_url");
user.profile = profile;
return user;
});
我正在尝试使用 github 对用户进行身份验证,然后将他们的 avatar_url
传递给客户端。简化的结构如下所示。
server/
publications.js
client/
users/
login.js
main.js
在我的 client/users/login.js
文件中,我尝试获取对包含头像 url
Accounts.ui.config({
requestPermissions: {
github: ['user']
}
});
然后在我的 server/publications.js
中,我尝试发布 the data related to the avatar url。
Meteor.publish('userData', function() {
if(this.userId) {
return Meteor.users.find(
{ _id: this.userId }, {
fields: {
'services.github.id': 1,
'services.github.user.avatar_url': 1
}
})
} else {
this.ready();
}
});
然而,当我得到我的用户对象时,我从来没有得到与 github 用户相关的数据。如何使用 OAuth 访问用户?
请查看此示例代码,您是否在 CreateUser 上捕获了 Github 配置文件数据?
编辑:这是服务器端代码,例如server/accounts.js
Accounts.onCreateUser(function (options, user) {
var accessToken = user.services.github.accessToken,
result,
profile;
result = Meteor.http.get("https://api.github.com/user", {
params: {
access_token: accessToken
}
});
if (result.error)
throw result.error;
profile = _.pick(result.data,
"login",
"name",
"avatar_url",
"url",
"company",
"blog",
"location",
"email",
"bio",
"html_url");
user.profile = profile;
return user;
});