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

查看:51
本文介绍了如何将外部服务登录名添加到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天全站免登陆