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.
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
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)
}
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.
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.
That's about it. I hope this helps future devs who are trying to figure out more complicated uses of SecureSocial.