Reputation: 3907
in an existing Silverlight application,I'm substituting WCF Services with ServiceStack's ones... I've successfully managed to port all the service and tested them..I've got one last point to look at...the authentication
Currently in I use an Asp.NET authentication based on a CustomMembershipProvider that checks with some criteria if a user can access to the application.
In each of my Services method I've something as
public bool DoSomething(int idUser, string prefix)
{
if (!HttpContext.Current.User.Identity.IsAuthenticated) throw new SecurityExeption();
//some computation
return res;
}
And it works fine... Now I was tring to implement the same thing on ServiceStack,I've created my AuthProvider as follow
public class myAuthProvider : CredentialsAuthProvider { public override bool TryAuthenticate(IServiceBase authService, string userName, string password) { if (userName == "test" && password == "test") return true;
return false;
//return base.TryAuthenticate(authService, userName, password);
}
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
authService.SaveSession(session, SessionExpiry);
}
}
And tested it on a sample project (I promise I'll remove test/test before deploying it!)
I've tried to check if HttpContext.Current.User.Identity.IsAuthenticated is valid after I've authenticated via SS Service but I got a false... am I doing something wrong or ServiceStack won't build authentication on asp.net? am I hinering from the wrong AuthProvider? I wish to have all the asp.net feauter persisted as sliding period/session timeout via web.config and so on
Thanks
Upvotes: 2
Views: 285
Reputation: 464
Possible Duplicate but may be different because you're on Silverlight.
Use ASP.NET Membership in ServiceStack
Based on Documentation:
"ServiceStack's Authentication, Caching and Session providers are completely new, clean, dependency-free testable APIs that doesn't rely on and is devoid of ASP.NET's existing membership, caching or session provider models."
https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization
If you're using a the service stack JsonServiceClient, there is nothing that will automatically fill in any authentication information in your request. Additionally, once you make your service run on ServiceStack, you're opting out of any MS built-in authentication schemes. See Mythz answer on how you can run an ASP.NET site side by side with a shared session and whether that can apply to your situation.
I have a hunch that in your custom Auth Provider, the username and password being passed in to TryAuthenticate is either NULL or empty.
Upvotes: 1