// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Configure the db context and user manager to use a single instance per request //app.CreatePerOwinContext(ApplicationDbContext.Create); //app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); // Enable the application to use a cookie to store information for the signed in user // and to use a cookie to temporarily store information about a user logging in with a third party login provider // Configure the sign in cookie app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); var configuration = new Configuration(); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); //app.UseFacebookAuthentication( // appId: "", // appSecret: ""); app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() { ClientId = configuration.Get<string>("GoogleClientId"), ClientSecret = configuration.Get<string>("GoogleClientSecret") }); }
private static bool TryGetValue(PropertyInfo propertyInfo, Configuration configuration, out object result) { result = null; var type = propertyInfo.PropertyType; var reflectedType = propertyInfo.ReflectedType; var keys = new[] { reflectedType.Name + propertyInfo.Name, propertyInfo.Name, }; var vals = from key in keys let attempt = configuration.ConvertValue(type, configuration.Get(key)) where attempt != null select attempt; foreach (var value in vals) { result = value; return(true); } return(false); }
public async Task<ActionResult> ExternalLoginCallback(string returnUrl) { var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return RedirectToAction("Login"); } var configuration = new Configuration(); var userList = configuration.Get<string>("UserList").Split(';'); if (!userList.Contains(loginInfo.Email)) { return RedirectToAction("Login"); } // Sign in the user with this external login provider if the user already has a login var user = await UserManager.FindAsync(loginInfo.Login); if (user != null) { await SignInAsync(user, isPersistent: false); return RedirectToLocal(returnUrl); } else { // If the user does not have an account, then prompt the user to create an account ViewBag.ReturnUrl = returnUrl; ViewBag.LoginProvider = loginInfo.Login.LoginProvider; return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email, Name = loginInfo.ExternalIdentity.Name}); } }
public TmdbMoviesService() { var config = new Configuration(); _client = new TMDbClient(config.Get<string>("TmdbApiKey")); _client.GetConfig(); }
private static object GetValueOrNull(Type type, string key, Configuration configuration) { try { return(type == typeof(ConnectionStringSettings) ? configuration.ConnectionString.Get(key) : configuration.ConvertValue(type, configuration.Get(key))); } catch (InvalidOperationException) { return(null); } }