检索accounts-github accesstoken

时间:2013-10-14 11:43:55

标签: meteor github-api

我正在编写使用GitHub API的第三方软件包。我现在正尝试使用accessToken包中的accounts-github来进行经过身份验证的GitHub API请求。

如何从accessToken检索accounts-github

1 个答案:

答案 0 :(得分:2)

如果您从服务器端执行此操作,请执行以下操作:

var user = Meteor.user().services.github.accessToken;

在客户端,它有点棘手,因为services字段未发布。如果运行发布方法,则可以按如下方式发布它:

Meteor.publish('account', function() {
    return Meteor.users.find({_id: this.userId},{fields:{services: 1}});
});

我建议您在创建用户时在配置文件中存储accessToken以及客户端上需要的任何其他内容。

Accounts.onCreateUser(function(options, user) {
    if (options.profile)
        user.profile = options.profile;
    user.profile.github_accessToken = user.services.github.accessToken;
    return user;
});

然后,您可以使用accessToken

访问客户端或服务器上的Meteor.user().profile.github_accessToken
相关问题