cgipson
cgipson

Reputation: 410

ServiceStack on .NET Core using Authorization Policies

Is there an example of using .NET Core authorization policies with ServiceStack based apis?

I have setup a .net core based ServiceStack site, I also have created an authorization policy. The next step, which I am having trouble with is injecting the authorization service into the ServiceStack implementation and passing in the user principal to the authorization service.

Upvotes: 2

Views: 316

Answers (1)

mythz
mythz

Reputation: 143319

Whilst ServiceStack doesn't know anything about .NET Core's Authentication, you can access the User assigned to the underlying .NET Core Request in your filters with:

GlobalRequestFilters.Add((req, res, requestDto) => {
    if (req.OriginalRequest is HttpRequest netcoreReq)
    {
        var user = netcoreReq.HttpContext.user;
    }
});

Upvotes: 1

Related Questions