I am having a few issues with the typescript client and Identity auth.
- When making request inside nextjs getStaticProps() the authentication request successeds but subsequent request will receive a 401. Same code in a server component in dev mode works fine.
export async function generateStaticParams() {
let client = JsonApiClient.create("https://localhost:5001");
client.credentials = "include";
let req = new Authenticate();
req.provider = "credentials";
req.userName = "user";
req.password = "pass";
const response = await client.post(req);
console.log("AUTH", response, client.cookies); //authenticates successfully and cookie present
let queryCompanies = new QueryCompanies();
const data = await client.get(queryCompanies); //401 when running in build with static export option but fine in dev mode
return [data];
}
- Can I get the bearer token in the response of an
Authenticate
request? I have tried posting tohttps://localhost:5001/session-to-token
to get a token to test with but it returns an empty object (cookie is present and can hit authenticated endpoint in postman). Ideally I want someone to login and get the token as a response.
relevant configs from my project (ServiceStack 8.2.3):
//plugin
services.AddPlugin(new AuthFeature(IdentityAuth.For<ApplicationUser>(options =>
{
options.SessionFactory = () => new CustomUserSession();
options.CredentialsAuth();
options.JwtAuth(x =>
{
x.IncludeConvertSessionToTokenService = true;
});
}
//program.cs
services.AddAuthentication()
.AddJwtBearer(options => {
options.TokenValidationParameters = new()
{
ValidIssuer = config["JwtBearer:ValidIssuer"],
ValidAudience = config["JwtBearer:ValidAudience"],
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(config["JwtBearer:IssuerSigningKey"])),
ValidateIssuerSigningKey = true,
};
})
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromDays(150);
options.SlidingExpiration = true;
options.Cookie.SameSite = SameSiteMode.None;
options.DisableRedirectsForApis();
});