We are trying to manually build some JWT tokens for various purposes according to the documentation at https://docs.servicestack.net/jwt-authprovider#creating-jwt-tokens-manually
But we keep getting this error: AuthKey required to use: HS256
Here is our Plugin setup:
new AuthFeature(() => new CustomAuthUserSession(), new IAuthProvider[]
{
new CustomAuthProvider()
{
PersistSession = true,
},
new CustomJwtAuthProvider()
{
AuthKeyBase64 = host.AppSettings.Get<string>("AuthKeyBase64"),
HashAlgorithm = "HS256"
RequireSecureConnection = false,
},
})
Here is our GenerateJwt method:
public string GenerateJwt(int userId)
{
var header = JwtAuthProvider.CreateJwtHeader(provider.HashAlgorithm);
var body = JwtAuthProvider.CreateJwtPayload(new CustomAuthUserSession()
{
UserAuthId = userId.ToString(),
FirstName = user.FirstName,
LastName = user.LastName,
FullName = user.FullName,
DisplayName = user.FullName,
Email = user.Email,
AgencyId = user.AgencyId,
StateAbbreviation = StateEnum.FromValue(agency.PrimaryStateId.Value).Abbreviation,
StateId = agency.PrimaryStateId.Value,
TimeZone = agency.Timezone
},
issuer: provider.Issuer,
expireIn: provider.ExpireTokensIn,
audiences: new[] {provider.Audience},
roles: roles,
permissions: perms);
var jwtToken = JwtAuthProvider.CreateJwt(header, body, provider.GetHashAlgorithm());
return jwtToken;
}
Am I misunderstanding where or how to set the AuthKey?
This line throws the error:
JwtAuthProvider.CreateJwt(header, body, provider.GetHashAlgorithm());