eadam
eadam

Reputation: 26161

use Owin OAuth 2.0 in multi tenant site

I am currently using Owin 2.0 in my multi tenant CMS. I need a way to change the facebook app id and secret depending on the tenant.

The problem is that Owin config code is executed before anything else. Request.Url is not the solution. Please suggest me a practical solution. Currently i can only differentiate between tenants from the url.

Upvotes: 0

Views: 964

Answers (1)

jd4u
jd4u

Reputation: 5807

Use this answer as a helpful tip and not a solution

You should use FacebookAuthenticationProvider to customize complete flow for each tenant. FacebookAuthenticationProvider has three events exposed that will help customization.

Tip: Use Object Browser in Visual Studio

FacebookAuthenticationOptions fbOptions = new FacebookAuthenticationOptions();
fbOptions.AppId = "DefaultAppId"; 
fbOptions.AppSecret = "DefaultSecret"; 
fbOptions.CallbackPath = new PathString("DefaultTenantWithCallBackUrl"); 
fbOptions.Provider = new FacebookAuthenticationProvider()
{
    OnApplyRedirect = (FacebookApplyRedirectContext context) =>
    {
         /*a way to change the facebook app id and secret depending on the tenant.*/
         /*Redirect to tenant specific built url */
    },
    OnAuthenticated = (FacebookAuthenticatedContext context) =>
    {
         /*process tenant specific logic*/
        return Task.FromResult(0);
    },
    OnReturnEndpoint = (FacebookReturnEndpointContext context) =>
    {
         /*process tenant specific logic*/
        return Task.FromResult(0);
    }
};
app.Use(typeof(FacebookAuthenticationMiddleware), app, fbOptions);

Upvotes: 3

Related Questions