In this code:
public override Task<IHttpResult> OnAuthenticatedAsync(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo, CancellationToken token = default)
{
// populate session with roles + permissions from autoRepo
var authRepo = authService.TryResolve<IAuthRepository>();
var userAuth = authRepo.GetUserAuthByUserName(session.UserAuthName);
var roles = authRepo.GetRoles(userAuth);
var permissions = authRepo.GetPermissions(userAuth);
session.Roles = roles.ToList();
session.Permissions = permissions.ToList();
// other stuff
return base.OnAuthenticatedAsync(authService, session, tokens, authInfo, token);
}
When I debug the session.Permissions is set to an empty list.
However when calling a regular service right after:
public class MyServices : Service {
public SomethingResponse Get(Something request)
{
var session = GetSession();
// session.Permissions is null
The session object inside the service has AuthProvider = “jwt”, if that is of any help, and it is configured like this:
new AuthUserSession(),
new JwtAuthProvider(AppSettings) {
AuthKeyBase64 = AppSettings.GetString("AuthKeyBase64"),
ExpireTokensIn = TimeSpan.FromHours(8), // default is 14 days
RequireSecureConnection=false, // SSL is terminated on the reverse proxy
},
Is there any reason Permissions is NULL instead of an empty list? Of course I can do a lot of NULL checks, or even use the ?.
operator everywhere, but if I forget I’ll have a bug.