Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
- {
- if (userName == "admin" && password == "test")
- return true;
- return false;
- }
- public override IHttpResult OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
- {
- try
- {
- base.OnAuthenticated(authService, session, tokens, authInfo);
- // Save the browser cookie.
- if (authService.Request is IHttpResponse httpRes)
- httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
- // Save the user session object (ServiceStack stores it in the in-memory cache).
- authService.SaveSession(session, this.SessionExpiry);
- return new HttpResult(HttpStatusCode.Accepted);
- }
- catch (Exception ex)
- {
- return new HttpResult(HttpStatusCode.ExpectationFailed);
- }
- }
- {
- "UserName": "admin",
- "Password": "test",
- "RememberMe": true }
- }
- using (var client = new JsonServiceClient("http://localhost:24131"))
- {
- client.AddHeader("Username", "admin");
- client.AddHeader("Password", "test");
- client.Post<HttpWebResponse>("/auth/credentials?format=json");
- response = client.Get(new GetProducts());
- }
Add Comment
Please, Sign In to add comment