Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. public class CredentialsAuthProvider : ServiceStack.Auth.CredentialsAuthProvider
  2. {
  3. public override bool TryAuthenticate(IServiceBase authService,
  4. string userName, string password)
  5. {
  6. //Add here your custom auth logic (database calls etc)
  7. //Return true if credentials are valid, otherwise false
  8. if (string.Compare(password, "123Eps123", true) == 0 && string.Compare(userName, "JBEps", true) == 0)
  9. return true;
  10. else
  11. return false;
  12. }
  13.  
  14. public override IHttpResult OnAuthenticated(IServiceBase authService,
  15. IAuthSession session, IAuthTokens tokens,
  16. Dictionary<string, string> authInfo)
  17. {
  18. //Fill IAuthSession with data you want to retrieve in the app eg:
  19. session.FirstName = "administrator";
  20. //...
  21.  
  22. //Call base method to Save Session and fire Auth/Session callbacks:
  23. return base.OnAuthenticated(authService, session, tokens, authInfo);
  24.  
  25. //Alternatively avoid built-in behavior and explicitly save session with
  26. //authService.SaveSession(session, SessionExpiry);
  27. //return null;
  28. }
  29. }
  30.  
  31. Plugins.Add(new AuthFeature(() => new AuthUserSession(),
  32. new IAuthProvider[] {
  33. new KCRouterLibreary.CredentialsAuthProvider(), //HTML Form post of User/Pass
  34. }
  35. ));
  36.  
  37. var _authenticate = function (sUsername, sPassword) {
  38. var parms = {};
  39. parms.userName = sUsername;
  40. parms.password = sPassword;
  41. parms.rememberMe = true;
  42. var promise = $http.post("http://" + sIP + ":20001/auth/credentials?format=json", parms).then(function (response) {
  43. var result = response.data.result;
  44. this.sessionID = response.data.sessionId;
  45. $http.defaults.headers.common['Authorization'] = 'Basic ' + this.sessionID;
  46.  
  47. initEventSource();
  48.  
  49. console.log("Logged in: " + this.sessionID);
  50. return result;
  51. });
  52.  
  53. return promise;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement