如何将外部服务登录添加到 Meteor 中的现有帐户? [英] How to add External Service logins to an already existing account in Meteor?

查看:15
本文介绍了如何将外部服务登录添加到 Meteor 中的现有帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为我的应用创建了个人资料页面后,我想显示用户所在的社交服务列表.我觉得最简单的方法是为此使用 Meteor 的内置帐户系统.

Having created a profile page for my app, I would like to display a list of social services that the user is on. It struck me that the easiest way would be to use Meteor's built in accounts system for this.

有没有什么好方法可以将外部服务添加到现有帐户中?

Is there a good way to add external services to an existing account?

此外,用户是否可以通过我的应用使用(例如)Facebook 他的密码登录?

Also, will the user then be able to log in with either (e.g.) Facebook and his password from my app?

自然而然出现的另一个问题:是否有一种好方法可以为使用外部服务创建的帐户添加特定于应用程序的密码?

Another question that naturally follows: Is there a good way to add an application specific password to an account that was created with an external service?

推荐答案

这是另一种方法.在这个解决方案中,我覆盖了一个核心功能并添加了一些自定义行为.我的目标是将服务数据与当前登录的用户相关联,然后让核心功能像往常一样做它的事情.

Here's an alternate method. In this solution, I'm overriding a core function and adding some custom behavior. My goal is to associate the service data with the currently logged in user, then allow the core function to do its thing like normal.

orig_updateOrCreateUserFromExternalService = Accounts.updateOrCreateUserFromExternalService;
Accounts.updateOrCreateUserFromExternalService = function(serviceName, serviceData, options) {
  var loggedInUser = Meteor.user();
  if(loggedInUser && typeof(loggedInUser.services[serviceName]) === "undefined") {
    var setAttr = {};
    setAttr["services." + serviceName] = serviceData;
    Meteor.users.update(loggedInUser._id, {$set: setAttr});
  }
  return orig_updateOrCreateUserFromExternalService.apply(this, arguments);
}

优点:

  • 避免创建不必要的帐户
  • 代码简短易懂
  • 如果将此功能添加到 Meteor 核心,代码很容易删除

缺点:

  • 要求用户登录.如果用户最初使用 Twitter 登录,然后注销,然后使用 facebook 登录,则会创建两个单独的帐户.
  • 共用一台计算机的用户可能会无意中合并他们的帐户.
  • 依赖于 updateOrCreateUserFromExternalService 如何工作的知识.这并不可怕——因为它是 Meteor 公共 api 的一部分,它可能不会发生巨大变化(反正也不经常).但这仍然有风险.

这篇关于如何将外部服务登录添加到 Meteor 中的现有帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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