josh-sachs
josh-sachs

Reputation: 1819

ServiceStack Twitter Auth and Registration

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

Upvotes: 0

Views: 154

Answers (2)

josh-sachs
josh-sachs

Reputation: 1819

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

Upvotes: 0

Darren Reid
Darren Reid

Reputation: 2322

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();

Upvotes: 1

Related Questions