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

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

问题描述

我使用允许使用外部服务登录的 Accounts-UI 和 Accounts-[Github/Twitter/Facebook/Google] 包.

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

我用 requestPermissions 修改了 Accounts.ui.config,例如:

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

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

但是当我使用 Github 登录时(例如),我只得到我的 Github 名称.

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

与其他外部服务相同.

如何获取更多信息,例如个人资料图片的网址?

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

推荐答案

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

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

您必须在回调函数中对服务进行额外调用以获取任何其他属性.目前,我所知道的无法直接插入 Meteor 用于获取身份属性的方法.

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.

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

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