Meteor login with external service: how to get profile information?

后端 未结 1 1546
北海茫月
北海茫月 2020-12-15 14:18

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

I modified Accounts.ui.config wit

相关标签:
1条回答
  • 2020-12-15 14:56

    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.

    0 讨论(0)
提交回复
热议问题