Val
Val

Reputation: 1033

Is this a bug in ServiceStack / Authentication?

Trying to use ServiceStack for authentication, and have it re-direct to a login page as follows:

Plugins.Add(new AuthFeature(
            () => new CustomUserSession(), //Use your own typed Custom UserSession type
            new IAuthProvider[] {
                new CredentialsAuthProvider(),              //HTML Form post of UserName/Password credentials
                new TwitterAuthProvider(appSettings),       //Sign-in with Twitter
                new FacebookAuthProvider(appSettings),      //Sign-in with Facebook
                new DigestAuthProvider(appSettings),        //Sign-in with Digest Auth
                new BasicAuthProvider(),                    //Sign-in with Basic Auth
                new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
                new YahooOpenIdOAuthProvider(appSettings),  //Sign-in with Yahoo OpenId
                new OpenIdOAuthProvider(appSettings),       //Sign-in with Custom OpenId
            }, "http://www.anyURIhereisignored.com"));

However the URI argument in this case "http://www.anyURIhereisignored.com" is simply ignored.

Looking at the class definition for AuthFeature, I see that the htmlRedirect param is declared as optional with a default value of "~/login", however it appears that it is always using that value and ignoring whatever was passed in. It seems that although the htmlRedirect value gets set initially to the passed URI, somehow internally it is never using that, instead always defaulting to "~/login". Is anyone else experiencing the same issue?

Upvotes: 1

Views: 322

Answers (2)

SteveChapman
SteveChapman

Reputation: 3081

If you're using MVC4 and your controllers are inheriting from the ServiceStackController<> as per the ServiceStack doco, then you may want to try overriding the LoginRedirectUrl property:

public override string LoginRedirectUrl
{
    get { return "/Account/Login?redirect={0}"; }
}

This will redirect any unauthenticated requests for secured actions to the login url composed from the specified value.

You should also make sure you remove the ASP.NET membership modules from the web.config if you want to use ServiceStack auth in MVC.

Upvotes: 1

MikeT
MikeT

Reputation: 827

I have a custom URI set as "~/account" and it is working fine. I tried changing it to google and the results was as you are looking for:

https://www.google.co.uk/?redirect=http://localhost/secure

Have you overridden the redirect in the attribute that indicates authentication is required ie.

[Authenticate(ApplyTo.All,"~/login")]

?

Upvotes: 1

Related Questions