是否将SecureSocial与后端用户服务/存储集成? [英] Integrate SecureSocial with backend user services/storages?

查看:51
本文介绍了是否将SecureSocial与后端用户服务/存储集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用播放! 2.0.4和SecureSocial 2( http://securesocial.ws/). Scala实施.这个问题大部分将直接在此处引用示例: https://github.com/jaliss/securesocial/blob/2.0.12/samples/scala/demo/app/service/InMemoryUserService.scala

Using Play! 2.0.4 and SecureSocial 2 (http://securesocial.ws/). Scala implementation. Most of this question will be directly referencing the sample here: https://github.com/jaliss/securesocial/blob/2.0.12/samples/scala/demo/app/service/InMemoryUserService.scala

我试图弄清楚作者与存储服务进行后端交互的初衷.关于def find(id: UserId)def findByEmailAndProvider(email: String, providerId: String):方法,SecureSocial是否期望提供可以返回完整SocialUser类的Facebook ID或电子邮件?

I'm trying to figure out the author's original intention as to backend interaction with a storage service. With respect to the def find(id: UserId) and the def findByEmailAndProvider(email: String, providerId: String): methods, is SecureSocial expecting to give either a Facebook ID or email that can be used to return a full SocialUser class?

如果是这种情况,那么我们如何为每个用户分配自己的ID,以便我们可以将帐户链接在一起?因为似乎如果我将身份扩展为包括通用ID,那么是否也需要重写/扩展社交提供程序?

If that's the case, then how do we assign our own IDs to each user so that we can link accounts together? Because it seems that if I extend Identity to include a universal ID then would that also require rewriting/extending the social providers, too?

至少,我试图弄清楚应该为后端服务中的findsave方法公开的API/参数.让我知道是否需要澄清这个问题:)

At minimum, I'm trying to figure out what API/parameters I should expose for the find and save methods in a backend service. Let me know if this question needs to be clarified :)

推荐答案

花了几天时间进行一些设计考虑并更好地理解SecureSocial之后,我意识到实现findsave方法并不难.理解.它正在适当地设计重要的后端服务中的逻辑.

After having a couple days to make some design considerations and better understand SecureSocial, I realized that implementing the find and save methods were not that difficult to understand. It's properly designing the logic in a backend service that matters.

基本上,我创建了一个PlatformUser类,该类扩展了Identity类,并包括从后端类提取的用户ID和配置文件数据.外观如下:

Basically, I created a PlatformUser class that extends the Identity class and includes User ID and profile data pulled from a backend class. Here's how it looks:

case class PlatformUser(
  guid: String,
  suspended: Boolean,
  id: UserId, 
  firstName: String, 
  lastName: String, 
  fullName: String, 
  email: Option[String],
  avatarUrl: Option[String], 
  authMethod: AuthenticationMethod,
  oAuth1Info: Option[OAuth1Info] = None,
  oAuth2Info: Option[OAuth2Info] = None,
  passwordInfo: Option[PasswordInfo] = None,
  communityProfile: Option[String] = None

) extends Identity

我的object PlatformUser包含访问后端HTTP API来回传输数据的代码.这是我实现findsave方法的方法:

My object PlatformUser contains code that accesses a backend HTTP API to transfer data back and forth. Here's how I implement the find and save methods:

  def find(id: UserId): Option[PlatformUser] = {
    PlatformUser.fetch(id)
  }

  def findByEmailAndProvider(email: String, providerId: String): Option[PlatformUser] = {
    PlatformUser.fetch(email, providerId)
  }

  def save(user: Identity): PlatformUser = {
    PlatformUser.store(user)
  }

合并帐户的逻辑也保留在后端服务中.现在,如果该用户尚不存在,则后端服务将生成一个平台ID.如果发现平台上已经存在传入Identity的电子邮件,则将身份自动链接到现有平台ID(除非发现该电子邮件已在同一社交网络的多个帐户中使用) ,其中将触发错误).通过电子邮件通知用户其自动链接的主要地址.

The logic for merging accounts remains in the backend service as well. Now if the user doesn't already exist, the backend service generates a platform ID. If an email of an incoming Identity is found to already exist on the platform, then an auto-link of identities is performed to the existing platform ID (unless its found that the email is being used on multiple accounts for the same social network, where an error will be triggered). The user is notified by email to their primary address of the auto-link.

最后剩下的是填充communityProfile.如果后端服务找不到,则该字段返回为None.然后,我自动将用户重定向到注册"页面,在该页面上他们需要完成个人资料.

The last thing left is populating the communityProfile. If the backend service doesn't find one, then that field returns as None. I then automatically redirect the user to a "registration" page where they need to complete their profile.

就是这样.我希望这对试图找出SecureSocial更复杂用法的未来开发人员有所帮助.

That's about it. I hope this helps future devs who are trying to figure out more complicated uses of SecureSocial.

这篇关于是否将SecureSocial与后端用户服务/存储集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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