Tech Cruize
Tech Cruize

Reputation: 107

Servicestack Authentication IsAuthenticated always false

Hi am trying to use OAuth authentication provided by servicestack

plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[]     {
new BasicAuthProvider(), new LinkedInOAuth2Provider(new AppSettings()),
new GoogleOAuth2Provider(new AppSettings()) }));

        //Use Redis Repo
        var userRepository = new RedisAuthRepository(redisClientsManager);
        container.Register<IUserAuthRepository>(userRepository);
        //Register Users with redis
        Plugins.Add(new RegistrationFeature());

After Successful authentication by Google/LinkedIn the redis AuthRepo contains this, We can see that isAuthenticated is False even after Successful authentication.

We can see that isAuthenticated is False

Could anyone let me know more about OAuth, Because there are many Secrets of it when comes to Mobile.

Eg: What Redirect Uri should i give in LinkedIn Console..! if i use OAuth for Mobiles ..? And how can i refresh session on each App StartUp.

Upvotes: 1

Views: 217

Answers (1)

mythz
mythz

Reputation: 143339

Your screenshot does not show an authenticated User Session, which would have IsAuthenticated = true and include OAuth details returned by each OAuth provider in ProviderOAuthAccess collection.

ServiceStack OAuth Live Demos

See the httpbenchmarks.servicestack.net for an example of a working Live Demo that uses Google and LinkedIn OAuth2. The HttpBenchmarks Github Repo includes a step-by-step Guide explaining how to Configure OAuth in ServiceStack, including an example of a App Settings configuration and how to configure Glimpse for inspecting DotNetOpenAuth errors.

The mvc.servicestack.net Live Demo is another example that contains a working configuration using a number of Auth Providers.

Use AppHost AppSettings

When registering the OAuth Provider you should use the AppHost's AppSettings instead of injecting a new AppSettings() that way all Auth Providers will use the same configured AppSettings for your AppHost, e.g:

Plugins.Add(new AuthFeature(() => new AuthUserSession(), 
    new IAuthProvider[] {
        new BasicAuthProvider(), 
        new LinkedInOAuth2Provider(base.AppSettings),
        new GoogleOAuth2Provider(base.AppSettings) 
    }));

Upvotes: 1

Related Questions