0
votes

I've got an app that has been running using CredentialsAuthProvider() for a while.

Today, I'd like to add twitter and facebook as options for people to create an account. I've got the scaffolding in place.

  //Register all Authentication methods you want to enable for this web app.            
  Plugins.Add(new AuthFeature(() => new AuthUserSession(),
    new IAuthProvider[] {
      new CredentialsAuthProvider(),
      new TwitterAuthProvider(appSettings),
      new FacebookAuthProvider(appSettings)
  }));


  //Provide service for new users to register so they can login with supplied credentials.
  Plugins.Add(new CustomRegistrationFeature());

The endpoints /api/auth/twitter and /api/auth/facebook work, and I see that a user session is created by visiting /api/auth once the OAuth process is complete HOWEVER...

No user is created in my UserAuthRepository (OrmLiteAuthRepository). The User Id stored in the session is invalid. Any method decorated with the [Authenticate] attribute causes a 404 (User not found) error to be returned.

I would expect that a user is created with the First/Last/Email obtained from Facebook or Twitter. Am I misunderstanding something?

ServiceStack v4.0.38

2
If you're still having trouble, try to create a minimal project to highlight the issue and post a link here. - Darren Reid
Ok i'll do that. I'm not able to get anything setup this week as I'm traveling, but will get something up ASAP. The crux of the issue is that a Session is being created by the twitter provider, but the database doesn't get the user added to it. Right now it just keeps creating a user with ID == 1 in my redis session store, but in my auth repo the no user gets created (it should have been a user with ID 4xxx). - josh-sachs

2 Answers

1
votes

A few things to check would be the oauth.CallbackUrl has been set correctly taking into account the multiple providers you have registered. Eg http://localhost/auth/{0}.

Also you should check if your IDbConnectionFactory used with your OrmLiteAuthRepository has also been registered with the IoC container. Eg

var dbFactory = new OrmLiteConnectionFactory(
    "~/App_Data/db.sqlite".MapHostAbsolutePath(),
    SqliteDialect.Provider);

container.Register<IDbConnectionFactory>(dbFactory);
var authRepo = new OrmLiteAuthRepository(dbFactory);
container.Register<IUserAuthRepository>(authRepo);

authRepo.InitSchema();
0
votes

I wanted to update this thread to say that I've upgraded to ServiceStack 4.0.42 and this issue has resolved itself.