流星登录外部服务:如何获取个人资料? [英] Meteor login with external service: how to get profile information?

查看:117
本文介绍了流星登录外部服务:如何获取个人资料?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Accounts-UI和Accounts- [Github / Twitter / Facebook / Google]软件包,允许使用外部服务登录。



我修改了 Accounts.ui.config with requestPermissions ,示例:

  Accounts.ui.config({
requestPermissions:{
github:['user'],
facebook:['user_photos']
}
});

但是,当我使用Github登录时(例如),我只能得到我的Github的名字。 p>

与其他外部服务相同的东西。



如何获取更多信息,如个人资料图片的URL? / p>

解决方案

您可以使用Accounts.onCreateUser(fn)方法自定义创建用户时存储的内容。以下是一些示例代码:

  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;
});

您必须在回调函数中额外调用该服务才能获取任何其他属性。目前,我没有办法直接插入Meteor用来获取身份属性的方法。


I use the Accounts-UI and Accounts-[Github/Twitter/Facebook/Google] packages which allows login with external service.

I modified Accounts.ui.config with requestPermissions, example:

Accounts.ui.config({
  requestPermissions: {
    github: ['user'],
    facebook: ['user_photos']
  }
});

But when I logged me with Github (for example), I get only my Github's name.

Same thing with others external services.

How to get more information, like the url of the profile picture?

解决方案

You can use the Accounts.onCreateUser(fn) method to customize what gets stored when the user is created. Here is some sample code:

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;
});

You have to make an additional call to the service in the callback function to grab any additional attributes. Currently, there's no way that I know of to plug directly into the method that Meteor uses to get the identity attributes.

这篇关于流星登录外部服务:如何获取个人资料?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆