Question

I'm using ASP.NET Identity 2 Framework (ASP.NET MVC 5) in a multi-tenanted application.

I can integrate a Facebook application easily. It can be configure it's scopes/credentials etc in Startup.cs.

But I have x domains and x Facebook applications, and I'll decide which credentials to use during runtime.

How can I change/set an external login providers settings dynamically rather than on application startup?

Was it helpful?

Solution

The Identity 2 Framework doesn't support setting or registering dynamic external login providers (such as being able to alter the Facebook clientId credentials for example). You will have to role our own solution manually.

The framework is based on OWIN and thus a controller can only pass messages to the authenication provider by the use of a shared context. The one that is provided by the ASP.NET Identity system doesn't support relaying these kind of messages (such as the credentials you want to alter). OWIN doesn't allow you to alter the settings of a MiddleWare object that has already been bound.

Further, the extension Microsoft provide for the Identity system for each of the main external login providers (i.e. Facebook) are structured using Internal classes that we cannot inherit from or modify. So this leaves us stuck.

You can role your own OWIN MiddleWare provider for facebook, and use a shared context - which is supposed to be the modern way of doing things. Or just use the regular MVC system to handle this. You could use the source code for their Identity Facebook Extension as a guide.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top