16

Stub User.Identity.IsAuthenticated in ASP Core

 4 years ago
source link: https://andersmalmgren.com/2019/04/23/stub-user-identity-isauthenticated-in-asp-core/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Stub User.Identity.IsAuthenticated in ASP Core

I’m writing this article strictly because google do not have any obvious solutions in the hope it will be indexed and presented for fellow devs.

We use identity server and to make things easier in dev I want to stub it. ClaimsIdentity takes a second argument AuthenticationType. Its important you set this property. You can set it to what ever you like. Once set IsAuthenticated will return true.

if (env.IsDevelopment())
{
app.Use(async (ctx, next) =>
{
ctx.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "local") }, "Authenticated"));
await next.Invoke();
});
}
Posted in Useful snippets and tagged Authentication, C#, Security on April 23, 2019. Leave a comment

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK