Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ServiceStack Custom Auth Provider
public class CustomAuthProvider : CredentialsAuthProvider
public override IHttpResult OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
var dbFactory = authService.ResolveService<IDbConnectionFactory>();
using (var db = dbFactory.Open())
var user = db.LoadSelect<User>(x => x.Email.ToLower() == session.UserAuthName.ToLower()).FirstOrDefault();
var roles = LoadRoles(db, user);
var permissions = LoadPermissions(db, user);
session.UserAuthId = user.Id.ToString();
session.FirstName = user.FirstName;
session.LastName = user.LastName;
session.DisplayName = user.FirstName + " " + user.LastName;
session.Email = user.Email;
session.UserName = user.Email;
session.Roles = roles;
session.Permissions = permissions;
return base.OnAuthenticated(authService, session, tokens, authInfo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.