1
votes

How can I make ServiceStack not creating multiple UserAuth with the same email address?

I do the following:

  • Create an account using Credentials(user + pass) & log in
  • Log Out
  • Sign In using Facebook (same email address as used in Credential)

This creates a new UserAuth and therefore a new User. Is it possible to tell the user who is trying to sign in using Facebook that the account with the Email address already exists?

I looked into subclassing FacebookAuthProvider and override Authenticate but I don't have the access to email from Facebook yet. Is there another method that I need to override? Similar question here but doesn't look like its been resolved?

Why doesn't ServiceStack always link UserAuth and UserAuthDetails?

1

1 Answers

1
votes

ServiceStack now verifies emails returned by OAuth providers are now unique in this commit where if there's already a UserAuth with an existing email authentication will fail and redirect (for HTML/Web Browser requests) with the Error message token:

/#f=EmailAlreadyExists

Otherwise if they're already authenticated with an existing Email Facebook authentication will succeed and the UserAuth accounts merged together.

A new CustomValidationFilter was also added to all AuthProviders which can be used to return a IHttpResult to control what error response is returned, e.g:

Plugins.Add(new AuthFeature(
    () => new CustomUserSession(), 
    new IAuthProvider[] {
        new FacebookAuthProvider(appSettings) { 
            CustomValidationFilter = authCtx => CustomIsValid(authCtx) 
                ? authCtx.Service.Redirect(authCtx.Session.ReferrerUrl
                    .AddHashParam("f","CustomErrorCode"))
                : null,
        },
    }));

This change will be available from v4.0.25+ that's now available on MyGet.