-
Notifications
You must be signed in to change notification settings - Fork 82
Bootstrapper Configuration
Bootstrapper configuration is used to setup providers in NancyFX. You can actually do it anywhere, so long as you register the AuthenticationService
with your IoC container of choice.
This wiki assumes you're using TinyIoC and registering directly in the bootstrapper.
Declare some private member variables for your Key/Secrets for each provider. You may also want to consider loading these from AppSettings or storing them somewhere that you can change them without changing you're code
private const string TwitterConsumerKey = "*key*";
private const string TwitterConsumerSecret = "*secret*";
private const string FacebookAppId = "*key*";
private const string FacebookAppSecret = "*secret*";
private const string GoogleConsumerKey = "*key*";
private const string GoogleConsumerSecret = "*secret*";
Override the RegisterAuthenticationProviders
method and create an instance of each provider you wish to register:
var twitterProvider = new TwitterProvider(TwitterConsumerKey, TwitterConsumerSecret);
var facebookProvider = new FacebookProvider(FacebookAppId, FacebookAppSecret);
var googleProvider = new GoogleProvider(GoogleConsumerKey, GoogleConsumerSecret);
Create an instance of the AuthenticationService class and register each provider with the service:
var authenticationService = new AuthenticationService();
authenticationService.AddProvider(twitterProvider);
authenticationService.AddProvider(facebookProvider);
authenticationService.AddProvider(googleProvider);
Lastly, register the service with the container:
container.Register<IAuthenticationService>(authenticationService);
The service should be registered as an instance so it acts like a singleton, there only needs to be one instance since they have no state. It simply gives you a redirection Url, or Returns you an authenticated user.
Your final method should be similar to:
private static void RegisterAuthenticationProviders(TinyIoCContainer container)
{
var twitterProvider = new TwitterProvider(TwitterConsumerKey, TwitterConsumerSecret);
var facebookProvider = new FacebookProvider(FacebookAppId, FacebookAppSecret);
var googleProvider = new GoogleProvider(GoogleConsumerKey, GoogleConsumerSecret);
var authenticationService = new AuthenticationService();
authenticationService.AddProvider(twitterProvider);
authenticationService.AddProvider(facebookProvider);
authenticationService.AddProvider(googleProvider);
container.Register<IAuthenticationService>(authenticationService);
}
- NancyFX Manual Setup
- NancyFX Automatic Setup
- MVC Manual Setup
- MVC Automatic Setup
- web.config
- global.asax
- bootstrapper