Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CredentialsAuthProvider : ServiceStack.Auth.CredentialsAuthProvider
- {
- public override bool TryAuthenticate(IServiceBase authService,
- string userName, string password)
- {
- //Add here your custom auth logic (database calls etc)
- //Return true if credentials are valid, otherwise false
- if (string.Compare(password, "123Eps123", true) == 0 && string.Compare(userName, "JBEps", true) == 0)
- return true;
- else
- return false;
- }
- public override IHttpResult OnAuthenticated(IServiceBase authService,
- IAuthSession session, IAuthTokens tokens,
- Dictionary<string, string> authInfo)
- {
- //Fill IAuthSession with data you want to retrieve in the app eg:
- session.FirstName = "administrator";
- //...
- //Call base method to Save Session and fire Auth/Session callbacks:
- return base.OnAuthenticated(authService, session, tokens, authInfo);
- //Alternatively avoid built-in behavior and explicitly save session with
- //authService.SaveSession(session, SessionExpiry);
- //return null;
- }
- }
- Plugins.Add(new AuthFeature(() => new AuthUserSession(),
- new IAuthProvider[] {
- new KCRouterLibreary.CredentialsAuthProvider(), //HTML Form post of User/Pass
- }
- ));
- var _authenticate = function (sUsername, sPassword) {
- var parms = {};
- parms.userName = sUsername;
- parms.password = sPassword;
- parms.rememberMe = true;
- var promise = $http.post("http://" + sIP + ":20001/auth/credentials?format=json", parms).then(function (response) {
- var result = response.data.result;
- this.sessionID = response.data.sessionId;
- $http.defaults.headers.common['Authorization'] = 'Basic ' + this.sessionID;
- initEventSource();
- console.log("Logged in: " + this.sessionID);
- return result;
- });
- return promise;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement