SergioC
SergioC

Reputation: 71

OWIN OAuth Token endpoint wildcard support

We are implementing a web api project using a base path for Tenant resolution (i.e. /Tenant/Api/controller)

We ran into problems implementing the auth code for the tenants. We would like to have a /{Tenant}/Token to enable auth request depending on the tenant. However we can't seem to map the token endpoint in OAuthAuthorizationServerOptions.

Any pointers to how we should proceed would be welcome.

Upvotes: 2

Views: 696

Answers (1)

Brock Allen
Brock Allen

Reputation: 7435

The OAuth2 AS MW has an event called OnMatchEndpoint where yuo can determine if the incoming request is an authorize request or a token request. It's meant for this exact type of check.

Something like this:

var authSvr = new OAuthAuthorizationServerOptions
{
    AllowInsecureHttp = true,
    AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive,
    //AuthorizeEndpointPath = new PathString("/authorize"),
    Provider = new OAuthAuthorizationServerProvider
    {
        OnMatchEndpoint = async ctx =>
        {
            if (ctx.Request.Uri.LocalPath == "/authorize")
            {
                ctx.MatchesAuthorizeEndpoint();
            }
        },

Except in yours you'd be more dynamic checking the ctx.Request.Uri.LocalPath for the tenant.

Upvotes: 4

Related Questions