public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider) { if (callbackProvider == null) { throw new ArgumentNullException("callbackProvider"); } _callbackProvider = callbackProvider; _authenticationProviderFactory = new AuthenticationProviderFactory(); }
public SimpleAuthenticationModule(IAuthenticationCallbackProvider callbackProvider) { _callbackProvider = callbackProvider; _authenticationProviderFactory = new AuthenticationProviderFactory(); // Define the routes and how they are handled. Get[RedirectRoute] = parameters => RedirectToProvider(parameters); Post[RedirectRoute] = parameters => RedirectToProvider(parameters); Get[CallbackRoute] = parameters => AuthenticateCallback(); }
public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider, ICache cache) { if (callbackProvider == null) { throw new ArgumentNullException("callbackProvider"); } _callbackProvider = callbackProvider; _cache = cache; // Can be null / not provided. _authenticationProviderFactory = new AuthenticationProviderFactory(); }
protected override void ConfigureApplicationContainer(TinyIoCContainer container) { base.ConfigureApplicationContainer(container); // database configuration var factory = new RepositoryFactory(); container.Register(factory.UserRepository); // security configuration var googleProvider = new GoogleProvider(new ProviderParams { PublicApiKey = GoogleClientId, SecretApiKey = GoogleSecret }); var authenticationProviderFactory = new AuthenticationProviderFactory(); authenticationProviderFactory.AddProvider(googleProvider); container.Register<IAuthenticationCallbackProvider>(new GoogleAuthenticationCallbackProvider(factory.UserRepository)); }
protected override void ConfigureApplicationContainer(TinyIoCContainer container) { base.ConfigureApplicationContainer(container); StaticConfiguration.DisableErrorTraces = false; FacebookProvider facebookProvider = new FacebookProvider(new ProviderParams { PublicApiKey = FacebookCredentials.FacebookAppId, SecretApiKey = FacebookCredentials.FacebookAppSecret }); AuthenticationProviderFactory authenticationProviderFactory = new AuthenticationProviderFactory(); authenticationProviderFactory.AddProvider(facebookProvider); container.Register<IAuthenticationCallbackProvider>(new SampleAuthenticationCallbackProvider()); }
protected override void ConfigureApplicationContainer(TinyIoCContainer container) { base.ConfigureApplicationContainer(container); var googleProvider = new GoogleProvider(new ProviderParams { PublicApiKey = GlobalConfig.GoogleConsumerKey, SecretApiKey = GlobalConfig.GoogleConsumerSecret }); var authenticationProviderFactory = new AuthenticationProviderFactory(); authenticationProviderFactory.AddProvider(googleProvider); container.Register<IAuthenticationCallbackProvider>(new RusserAuthenticationCallbackProvider()); }
protected override void ConfigureApplicationContainer(TinyIoCContainer container) { base.ConfigureApplicationContainer(container); //var twitterProvider = new TwitterProvider(new ProviderParams { PublicApiKey = TwitterConsumerKey, SecretApiKey = TwitterConsumerSecret }); var facebookProvider = new FacebookProvider(new ProviderParams { PublicApiKey = FacebookAppId, SecretApiKey = FacebookAppSecret }); var googleProvider = new GoogleProvider(new ProviderParams { PublicApiKey = GoogleConsumerKey, SecretApiKey = GoogleConsumerSecret }); var authenticationProviderFactory = new AuthenticationProviderFactory(); //authenticationProviderFactory.AddProvider(twitterProvider); authenticationProviderFactory.AddProvider(facebookProvider); authenticationProviderFactory.AddProvider(googleProvider); container.Register<IAuthenticationCallbackProvider>(new MedSetAuthenticationCallbackProvider()); }
// The bootstrapper enables you to reconfigure the composition of the framework, // by overriding the various methods and properties. // For more information https://github.com/NancyFx/Nancy/wiki/Bootstrapper protected override void ConfigureRequestContainer(Nancy.TinyIoc.TinyIoCContainer container, NancyContext context) { base.ConfigureRequestContainer(container, context); var githubAuth = new GitHubProvider(new ProviderParams() { PublicApiKey = Environment.GetEnvironmentVariable("PEASANT_OAUTH_ID") ?? "68e704a8ede918f8d940", SecretApiKey = Environment.GetEnvironmentVariable("PEASANT_OAUTH_KEY") ?? "888b305d22b2d7251b087c5903be21f7eaca4e20", Scopes = new[] { "repo", "user", "status", } }); var authServiceFactory = new AuthenticationProviderFactory(); authServiceFactory.AddProvider(githubAuth); container.Register<IAuthenticationCallbackProvider>(new AuthenticationCallbackProvider()); BlobCache.ApplicationName = "Peasant"; }
public object GetData(ITabContext context) { var tabSection = Plugin.Create("", "Name", "Type", "Public Key", "Private Key", "Scopes"); // Grab the registered authentication providers. var authenticationService = new AuthenticationProviderFactory(); var registeredProviders = authenticationService.AuthenticationProviders.Values; if (registeredProviders.Any()) { int count = 1; foreach (var registeredProvider in registeredProviders) { string publicApiKey = "-", secretApiKey = "-", scopes = "-"; var scopedProvider = registeredProvider as IScopedProvider; if (scopedProvider != null) { scopes = String.Join(scopedProvider.ScopeSeparator, scopedProvider.Scopes == null || !scopedProvider.Scopes.Any() ? scopedProvider.DefaultScopes : scopedProvider.Scopes); } var publicPrivateKeyProvider = registeredProvider as IPublicPrivateKeyProvider; if (publicPrivateKeyProvider != null) { publicApiKey = publicPrivateKeyProvider.PublicApiKey; secretApiKey = publicPrivateKeyProvider.SecretApiKey; } tabSection.AddRow() .Column(count++) .Column(registeredProvider.Name) .Column(registeredProvider.AuthenticationType) .Column(publicApiKey) .Column(secretApiKey) .Column(scopes); } } return tabSection; }
public AuthenticationService(AuthenticationProviderFactory factory, ApplicationSettings appSettings) { _factory = factory; if (!String.IsNullOrWhiteSpace(appSettings.FacebookAppId) && !String.IsNullOrWhiteSpace(appSettings.FacebookAppSecret)) { _factory.AddProvider(new FacebookProvider(new ProviderParams { PublicApiKey = appSettings.FacebookAppId, SecretApiKey = appSettings.FacebookAppSecret })); } else { _factory.RemoveProvider("facebook"); } if (!String.IsNullOrWhiteSpace(appSettings.TwitterConsumerKey) && !String.IsNullOrWhiteSpace(appSettings.TwitterConsumerSecret)) { _factory.AddProvider(new TwitterProvider(new ProviderParams { PublicApiKey = appSettings.TwitterConsumerKey, SecretApiKey = appSettings.TwitterConsumerSecret })); } else { _factory.RemoveProvider("twitter"); } if (!String.IsNullOrWhiteSpace(appSettings.GoogleClientID) && !String.IsNullOrWhiteSpace(appSettings.GoogleClientSecret)) { _factory.AddProvider(new GoogleProvider(new ProviderParams { PublicApiKey = appSettings.GoogleClientID, SecretApiKey = appSettings.GoogleClientSecret })); } else { _factory.RemoveProvider("google"); } }
public SimpleAuthenticationModule(IAuthenticationCallbackProvider callbackProvider) { _callbackProvider = callbackProvider; _authenticationProviderFactory = new AuthenticationProviderFactory(); // Define the routes and how they are handled. Get[RedirectRoute] = parameters => RedirectToProvider(parameters); Post[RedirectRoute] = parameters => RedirectToProvider(parameters); Get[CallbackRoute] = parameters => AuthenticateCallback(); // If no Cache type is provided, we'll use a Session as the default. Before += context => { if (Cache == null) { Cache = new SessionCache(context.Request.Session); } return null; }; }
public AuthenticationService(AuthenticationProviderFactory factory) { _factory = factory; }
public KeyRockModule(IAuthenticationCallbackProvider callbackProvider) { Before += context => { if (Cache == null) { Cache = new SessionCache(context.Request.Session); } return null; }; _callbackProvider = callbackProvider; _authenticationProviderFactory = new AuthenticationProviderFactory(); Get["/authenticate/keyrock"] = parameters => { var providerKey = (string)Request.Query.providerkey; if (string.IsNullOrEmpty(providerKey)) { throw new ArgumentException( "ProviderKey value missing. You need to supply a valid provider key so we know where to redirect the user Eg. providerkey=google."); } var previousRedirectUrl = string.IsNullOrEmpty((string)Cache[SessionKeyRedirectToProviderUrl]) ? "N.A." : (string)Cache[SessionKeyRedirectToProviderUrl]; #region Deserialize Tokens, etc. // Retrieve any (previously) serialized access token stuff. (eg. public/private keys and state). // TODO: Check if this is an access token or an auth token thingy-thing. var state = Cache[SessionKeyState] as string; var redirectToUrl = Cache[SessionKeyRedirectToUrl] as string; #endregion // Lets now start to setup the view model. var model = new AuthenticateCallbackData(); #region Retrieve the User Information try { // Which provider did we just authenticate with? var provider = _authenticationProviderFactory.AuthenticationProviders["keyrock"]; // Where do we return to, after we've authenticated? var callbackUri = GenerateCallbackUri(provider.Name); var queryString = new NameValueCollection(); foreach (var key in Request.Query.Keys) { queryString.Add(key, Request.Query[key]); } // Grab the user information. model.AuthenticatedClient = provider.AuthenticateClient(queryString, state, callbackUri); } catch (Exception exception) { model.Exception = exception; } #endregion // Do we have an optional redirect resource? Usually a previous referer? if (redirectToUrl != null) { model.ReturnUrl = redirectToUrl; } // Finally! We can hand over the logic to the consumer to do whatever they want. return _callbackProvider.Process(this, model); }; Get["/authentication/redirect/keyrock"] = _ => { var provider = _authenticationProviderFactory.AuthenticationProviders["keyrock"]; //// Most providers don't need any pre-setup crap, to redirect to authenticate. //// But of course, there's always one - OpenId. We have no idea WHERE we want to //// redirect to, so we need to do a particular check here. //// Of course, any value here could be used for any other provider. But that would be weird. //// TODO: Confirm this is not a security threat / open to abuse in some way. //if (identifier != null) //{ // provider.AuthenticateRedirectionUrl = identifier; //} //// Where do we return to, after we've authenticated? var callbackUri = GenerateCallbackUri("keyrock"); // Determine where we need to redirect to. var redirectToAuthenticateSettings = provider.RedirectToAuthenticate(callbackUri); // Remember any important information for after we've come back. Cache[SessionKeyState] = redirectToAuthenticateSettings.State; Cache[SessionKeyRedirectToUrl] = DetermineReturnUrl(); Cache[SessionKeyRedirectToProviderUrl] = redirectToAuthenticateSettings.RedirectUri.AbsoluteUri; // Now redirect :) return Response.AsRedirect(redirectToAuthenticateSettings.RedirectUri.AbsoluteUri); }; }