Guest User

Untitled

a guest
Jun 13th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
  2. {
  3. if (userName == "admin" && password == "test")
  4. return true;
  5.  
  6. return false;
  7. }
  8.  
  9. public override IHttpResult OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
  10. {
  11. try
  12. {
  13. base.OnAuthenticated(authService, session, tokens, authInfo);
  14.  
  15. // Save the browser cookie.
  16. if (authService.Request is IHttpResponse httpRes)
  17. httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
  18.  
  19. // Save the user session object (ServiceStack stores it in the in-memory cache).
  20. authService.SaveSession(session, this.SessionExpiry);
  21.  
  22. return new HttpResult(HttpStatusCode.Accepted);
  23. }
  24. catch (Exception ex)
  25. {
  26. return new HttpResult(HttpStatusCode.ExpectationFailed);
  27. }
  28. }
  29.  
  30. {
  31. "UserName": "admin",
  32. "Password": "test",
  33. "RememberMe": true }
  34. }
  35.  
  36. using (var client = new JsonServiceClient("http://localhost:24131"))
  37. {
  38. client.AddHeader("Username", "admin");
  39. client.AddHeader("Password", "test");
  40. client.Post<HttpWebResponse>("/auth/credentials?format=json");
  41.  
  42. response = client.Get(new GetProducts());
  43. }
Add Comment
Please, Sign In to add comment