Robin Bouwmeester
Robin Bouwmeester

Reputation: 63

How can we generate a jwt bearertoken on ServiceStack client side to impersonate a user?

Scenario:

Because Windows Authentication does not support passing thru the authentication, due the double-hop problem, we need to use an alternative solution to impersonate that user.

The ASP.NET website and the ServiceStack API website shares the same BearerTokenKey (to generate bearertokens).

We tried this by using the CreateJwtBearerToken() function of the JwtAuthProvider.cs, but then we get an exception that the AppHost is not initialized.

ConfigurationErrorsException

We don't want to startup or initialize ServiceStack on the ASP.NET website, but we only want to generate JWT bearer token keys on the client with the same shares BearerTokenKey between the ASP.NET website and the ServiceStack API.

Is there a way to generate the JWT bearer token key on the ASP.NET website without initializing any ServiceStack app host and which will be accepted by the ServiceStack API (indirect thru the JwtSecurityTokenHandler.cs)?

Upvotes: 1

Views: 154

Answers (1)

mythz
mythz

Reputation: 143369

Many of ServiceStack APIs require an AppHost, as you don't want to initialize a full AppHost, you can use an initialize a stub BasicAppHost instead, as done in integration tests:

using var appHost = new BasicAppHost().Init();

Upvotes: 2

Related Questions