0

I have implemented CredentialsAuthProvider authentication in ServiceStack.As a result of which i am able to create UserAuth and UserOAuthProvider tables into my RDBMS. Also i have written Service to register User. Now When i am trying to test my authentication using http://localhost:64132/auth/credentials URL i am able to do it. Also i am getting a response like

{
"SessionId": "1",
"UserName": "Bond",
"ResponseStatus": {}
}

Now as per my requirement i have to Consume this 'http://localhost:64132/auth/credentials' through my Login Service and get the response . On Successful authentication i want my Login Service to redirect to a Home.html page. Please help me to get it .I for the first time working on ServiceStack framework.Thanks

Update..

public class LoginService: Service {

        public Object Any(Login loginRequest) {

        //Here at this point call the Authentication URL from c# Client Service

        loginRequest.UserName = "Bond";
        loginRequest.Password = "password";

        string BaseUrl = "http://localhost:64132/auth";

        var client = new JsonServiceClient(BaseUrl);

        string response="";

        try
        {
            var authResponse = client.Send<AuthResponse>(new Auth
            {
                provider = CredentialsAuthProvider.Name,
                UserName = loginRequest.UserName,
                Password = loginRequest.Password,
                RememberMe = true,  //important tell client to retain permanent cookies
            });

            response = authResponse.ToString();
        }
        catch (Exception ex) { 

        }
Lara
  • 2,821
  • 7
  • 39
  • 72

1 Answers1

1

I've already answered this question for you in this previous answer listing each of the Redirect options, e.g you can use the ?Continue=/Home Request parameter when you authenticate.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks for your suggestion.I have a doubt : Is the Authentication in ServiceStack meant only for Services or it is also meant for User or Account Management , I mean creation of new User, Change of password , delete , etc ? – Lara Sep 18 '15 at 10:12
  • The AuthFeature just does authentication, you'd need to include the RegistrationFeature to enable the services for registering users for CredentialsAuth, see the [HttpBenchmarks Authentication docs](https://github.com/ServiceStackApps/HttpBenchmarks#authentication) for an example. – mythz Sep 18 '15 at 10:24
  • This i know Mythz and i am able to create or register users successfully . Only i am having problem in login using the credentials that i have registered using `RegistrationFeature` . I will explain a little more. I have a Login Service which is not authenticated so that all users can access this service .Now in this service i am passing registered user details like Username, password, etc.Now i want it to give me the successful or failure login response as per the credentials passed by the user. I am updating my question with my code ..please have a look and tell me where i am going wrong .. – Lara Sep 18 '15 at 10:29
  • 1
    @Lara you don't want to use a HTTP client to call another Service when you can [resolve it directly as seen in MVC demo](https://github.com/ServiceStack/Test/blob/master/src/Mvc/Mvc/Controllers/HomeController.cs#L38) or the [RegisterService impl](https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/Auth/RegisterService.cs#L106). To redirect you can just 'return HttpResult.Redirect("/Home")'. – mythz Sep 18 '15 at 10:43
  • I got your point. A small query : In RDBMS i have got two tables .What is the significance or use of `UserOAuthProvider` table and why is that used for ? – Lara Sep 18 '15 at 11:10
  • @Lara `UserOAuthProvider` is for persisting Users Info that authenticated via OAuth, this was renamed to `UserAuthDetails` in v4. If you're only using v3 of ServiceStack please [tag your questions with servicestack-bsd instead](https://github.com/ServiceStackV3/ServiceStackV3#support). – mythz Sep 18 '15 at 17:07