*It’s very common to create roles, and assign permissions to roles. *
*Checking would be against permissions only. *
Now we can add a user to one or more roles, and also give ad-hoc permissions of necessary.
I’ve implemented this solution:
public class MyOrmLiteAuthRepository : OrmLiteAuthRepository
{
public override ICollection<string> GetPermissions(string userAuthId) {
// gets permissions for roles, using OrmLite, returning them
}
}
This returns correct permissions, which I’ve verified in the debugger.
My custom Credentials provider:
public class LdapCredentialsAuthProvider : CredentialsAuthProvider
{
//...
public override Task<IHttpResult> OnAuthenticatedAsync(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo, CancellationToken token = default)
{
session.Permissions = authRepo.GetPermissions(userAuth).ToList();
base.OnAuthenticatedAsync(authService, session, tokens, authInfo, token);
}
}
I’ve verified it inserts all the permissions into the session, which I see with the debugger.
Problem:
Once inside a Service:
var session = GetSession();
session.Permissions // contains only the permissions inside the UserAuth table
// missing what was inserted during logon in OnAuthenticatedAsync()
Where did the permissions get lost? I’ve logged out and in, restarted the app many times etc. Is it stuck with JWT somehow?
This is my Configure.Auth:
appHost.Plugins.Add(new AuthFeature(() =>
new AuthUserSession(),
new IAuthProvider[] {
new LdapCredentialsAuthProvider(AppSettings),
new JwtAuthProvider(AppSettings) {
// generate key: Convert.ToBase64String(AesUtils.CreateKey())
AuthKeyBase64 = AppSettings.GetString("AuthKeyBase64"),
ExpireTokensIn = TimeSpan.FromHours(8), // default is 14 days
RequireSecureConnection=false, // SSL is terminated on the reverse proxy
},
}
)
Using this to logon: /auth/Credentials?UseTokenCookie=1
Chrome’s debugger shows this is returned from SS:
{"userId":"9","sessionId":"mPl8PJfvRJnaLrmYE3Dq","userName":"xxxx","displayName":"xxxx","profileUrl":"","roles":["Admin"],"permissions":["ImpersonateUser"]}
clearly missing the permissions added in OnAuthenticatedAsync.