Hi Mythz,
So I am trying to integrate JWT auth provider alongside our normal AspNet Auth provider(setup below) where I have manually created the secret key and appended in web.config.
var authFeature = new AuthFeature(() =>
new MyAppUserSession(),
new IAuthProvider[]
{
new JwtAuthProvider(AppSettings)
{
RequireSecureConnection = false,
LoadUserAuthFilter = (userSession, tokens, authInfo) => {
UserAuth.LoadUser(this.GetContainer(), userSession, tokens, authInfo);
}
},
new AspNetWindowsAuthProvider(this)
{
LoadUserAuthFilter = (userSession, tokens, authInfo) => {
UserAuth.LoadUser(this.GetContainer(), userSession, tokens, authInfo);
},
AllowAllWindowsAuthUsers = true
}
}
);
That UserAuth.LoadUser just basically contacts AD gets more record details populates that into MyAppUserSession
and then gets the Roles and Permissions from our Db.
Then my services have
[RequiredRole] and [RequiredPermission] implemented to further check against the right user with the right roles/permissions.
Furthermore, in my IIS I under Authentication I have everything disabled except for Windows Auth: Enabled.
(I have a feeling maybe I have to enable Anonymous Auth to be Enabled too?)
Then, I do the following to request for api but I get an Unauthorized from the servicestack.
public class MyClient : JsonServiceClient
{
ctor()
{
this.RequestFilter = req =>
{
var token = GetJwtToken(__payload__, my_secret) // this internally just uses this [lib](https://github.com/jwt-dotnet/jwt/blob/master/src/JWT/JwtEncoder.cs);
req.AddBearerToken(token);
}
}
// and __payload__ is populated like following:-
payload.Add("exp", (int)DateTime.UtcNow.AddHours(1).Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
payload.Add("iss", "SP-CustomScripts");
payload.Add("iat", (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
payload.Add("prn", userName);
}
and then the service returns “Unauthorized”.
Thanks,