Example #1
1
        public static void ConfigureAdditionalIdentityProviders(IAppBuilder app, string signInAsType)
        {
            var google = new GoogleOAuth2AuthenticationOptions
            {
                AuthenticationType = "Google",
                SignInAsAuthenticationType = signInAsType,
                ClientId = "client", //"767400843187-8boio83mb57ruogr9af9ut09fkg56b27.apps.googleusercontent.com",
                ClientSecret = "secret"  //"5fWcBT0udKY7_b6E3gEiJlze"
            };
            app.UseGoogleAuthentication(google);

            var fb = new FacebookAuthenticationOptions
            {
                AuthenticationType = "Facebook",
                SignInAsAuthenticationType = signInAsType,
                AppId = "app", //"676607329068058",
                AppSecret = "secret"  //"9d6ab75f921942e61fb43a9b1fc25c63"
            };
            app.UseFacebookAuthentication(fb);

            var twitter = new TwitterAuthenticationOptions
            {
                AuthenticationType = "Twitter",
                SignInAsAuthenticationType = signInAsType,
                ConsumerKey = "consumer",  //"N8r8w7PIepwtZZwtH066kMlmq",
                ConsumerSecret = "secret"  //"df15L2x6kNI50E4PYcHS0ImBQlcGIt6huET8gQN41VFpUCwNjM"
            };
            app.UseTwitterAuthentication(twitter);
        }
Example #2
1
        public static void Configure(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
              AuthenticationType = DefaultAuthenticationTypes.ExternalCookie
            });

            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Configure google authentication
            var options = new GoogleOAuth2AuthenticationOptions()
            {
              ClientId = "your app client id",
              ClientSecret = "your app client secret"
            };

            app.UseGoogleAuthentication(options);

            facebookAuthOptions = new FacebookAuthenticationOptions()
            {
            AppId = "528982800546743",
            AppSecret = "a6ee5ad8448c7c67fcedc72d5a4c501a",
            Provider = new FacebookAuthProvider()
            };

            app.UseFacebookAuthentication(facebookAuthOptions);
        }
        public static void ConfigureSocialIdentityProviders(IAppBuilder app, string signInAsType)
        {
            var google = new GoogleAuthenticationOptions
            {
                AuthenticationType = "Google",
                SignInAsAuthenticationType = signInAsType
            };
            app.UseGoogleAuthentication(google);

            var fb = new FacebookAuthenticationOptions
            {
                AuthenticationType = "Facebook",
                SignInAsAuthenticationType = signInAsType,
                AppId = "676607329068058",
                AppSecret = "9d6ab75f921942e61fb43a9b1fc25c63"
            };
            app.UseFacebookAuthentication(fb);

            var twitter = new TwitterAuthenticationOptions
            {
                AuthenticationType = "Twitter",
                SignInAsAuthenticationType = signInAsType,
                ConsumerKey = "N8r8w7PIepwtZZwtH066kMlmq",
                ConsumerSecret = "df15L2x6kNI50E4PYcHS0ImBQlcGIt6huET8gQN41VFpUCwNjM"
            };
            app.UseTwitterAuthentication(twitter);
        }
        private void ConfigureOAuth(IAppBuilder app)
        {
            app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

            OAuthAuthorizationServerOptions oAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new SimpleAuthorizationServerProvider(new AccountRepository())
            };

            GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId = "592613624399-a3gr6vveaocnptgvv6738rmnk0pb5cev.apps.googleusercontent.com",
                ClientSecret = "FqNKKib_BP7dsNYBoJa8NwUC",
                Provider = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(GoogleAuthOptions);

            FacebookAuthOptions = new FacebookAuthenticationOptions()
            {
                AppId = "806191272841558",
                AppSecret = "1a8241e9d46c4a5e393ae51f265a3489",
                Provider = new FacebookAuthProvider()
            };
            app.UseFacebookAuthentication(FacebookAuthOptions);

            // Token Generation
            app.UseOAuthAuthorizationServer(oAuthServerOptions);
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // 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: "");

            var facebookAuthenticationOptions = new FacebookAuthenticationOptions
            {
                AppId = "1480656632147712",
                AppSecret = "971e8d74e63d9a6a5e676bebd5c134ff"
            };
            facebookAuthenticationOptions.Scope.Add("email");
            app.UseFacebookAuthentication(facebookAuthenticationOptions);

            app.UseGoogleAuthentication();
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "813157725361099",
               appSecret: "4d2693d2689c9142ef4d0ea4276b0ee9");

            app.UseGoogleAuthentication(
                clientId: "422569705562-m9cbq7o7jt38pln1kio27qg9u0qrvjsl.apps.googleusercontent.com",
                clientSecret: "SY8I2NEOcj67wsUDGOf76ivL"
                );
        }
Example #7
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "1402226523379094",
               appSecret: "c64d30bf9c2c55cd0f2a1ca5d8dd6508");

            app.UseGoogleAuthentication();
        }
Example #8
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // 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
            app.UseCookieAuthentication( new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString( "/Account/Login" )
            } );
            app.UseExternalSignInCookie( DefaultAuthenticationTypes.ExternalCookie );

            // Uncomment the following lines to enable logging in with third party login providers
            app.UseMicrosoftAccountAuthentication(
                clientId: "000000004810F526",
                clientSecret: "f8LRRVF20XHwK6N58e4I9r99SEC7Ao0S" );

            app.UseTwitterAuthentication(
               consumerKey: "PqRSqRIrWw8EJty1Gat0ZA",
               consumerSecret: "gsElizO6qYGPA1RMApWdp1BpsmfvRYXXBWmd0hs8" );

            app.UseFacebookAuthentication(
               appId: "449783478408068",
               appSecret: "a058d3068f6b29bc0149e5987b9e823a" );

            app.UseGoogleAuthentication();
        }
        public void ConfigureAuth(IAppBuilder app)
        {
            app.CreatePerOwinContext(MyFollowContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, int>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
                    getUserIdCallback: (claim) => int.Parse(claim.GetUserId()))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            app.UseFacebookAuthentication(
               appId: "946468195376138",
               appSecret: "e327c6fcd1540a1e215c5b14d3684b11");

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "1015938086259-kc2u0pt7etjp91rfv1mfemtceb8nlng0.apps.googleusercontent.com",
            //    ClientSecret = "bfFVTrn60mcwHmKRQGFXze3n"
            //});
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "159445200858126",
               appSecret: "ce8ab57ee06d67db22ed156428a44b96");

            //app.UseGoogleAuthentication();
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "133426213508895",
               appSecret: "fc61d3139052096dcab386dd17b54b70");

            app.UseGoogleAuthentication();
        }
Example #12
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            //change the id and secret toconnect to your application
            app.UseFacebookAuthentication(
               appId: "574609735957646",
               appSecret: "4339c983ffa2685c1b09d580e3380455");

            app.UseGoogleAuthentication();
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301883
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            // and also store information about a user logging in with a third party login provider.
            // This is required if your application allows users to login
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "1641073876116354",
               appSecret: "54c572f2421e8404e391c5561d5435da");

            //app.UseGoogleAuthentication();
        }
Example #14
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "460137580825206",
               appSecret: "");

            app.UseGoogleAuthentication(clientId: "-nq90vhijsnjdtplr12n39rdaeprql98m.apps.googleusercontent.com", clientSecret: "");
        }
Example #15
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // 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
            app.UseSignInCookies();

            // Enable the application to use a cookie to store information for the signed in user
            app.UseApplicationSignInCookie();

            // Enable the application to use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie();

            // 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();
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // 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
            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enable the application to use bearer tokens to authenticate users
            app.UseOAuthBearerTokens(OAuthOptions);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //    consumerKey: "",
            //    consumerSecret: "");

            app.UseFacebookAuthentication(
                appId: "yourappid",
                appSecret: "yourappsecret");

            //app.UseGoogleAuthentication();
        }
Example #17
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            app.UseMicrosoftAccountAuthentication(
                clientId: "0000000040110865",
                clientSecret: "sk6T9LprRnHlnk74IJmz6z5NcAjyGKtm");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "244418352318084",
               appSecret: "f39b49a290337ef6d848723cea64507b");

            app.UseGoogleAuthentication();
        }
        // Pour plus d’informations sur la configuration de l’authentification, rendez-vous sur http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Autoriser l’application à utiliser un cookie pour stocker des informations pour l’utilisateur connecté
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Supprimer les commentaires des lignes suivantes pour autoriser la connexion avec des fournisseurs de connexions tiers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "1677086355911298",
               appSecret: "01abf5673bdcb38e4a773dc617137487");

            //app.UseGoogleAuthentication();
        }
Example #19
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Cheetah/UserAccount/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "0000000044101607",
            //    clientSecret: "CHfsN46nyXCEWAhB8LkJc3fLPSfg7uJh");

            //app.UseTwitterAuthentication(
            //    consumerKey: "76a8dqXzLrKEaAYP9AmdfnD5l",
            //    consumerSecret: "gnHfZQIXjcAIqDf5AxC3gslD3dIgjHeuEpA1RBgAvcSfQ4uRd3");

            app.UseFacebookAuthentication(
                appId: "600065163358974",
                appSecret: "71438dd894d191bd161a69720fbf10e1");

            app.UseGoogleAuthentication(clientId: "212507878610-9jd5t3vggkc8soi27ou449foi2cropau.apps.googleusercontent.com", clientSecret: "UiJxJI83jTt1XWpYZvxDxd0I");
        }
Example #20
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "628591770609919",
               appSecret: "8bd0cb413f879fb7d6f12f3b7a5d6bd6");

            //app.UseGoogleAuthentication();
        }
Example #21
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            app.UseCors(new CorsOptions {PolicyProvider = new CustomOwinCorsPolicyProvider()});

            // 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
            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            
            // Enable the application to use bearer tokens to authenticate users
            app.UseOAuthBearerTokens(OAuthOptions);

            // Uncomment the following lines to enable logging in with third party login providers
            app.UseMicrosoftAccountAuthentication(
                clientId: ConfigurationManager.AppSettings.Get("OAuthMicrosoftKey"),
                clientSecret: ConfigurationManager.AppSettings.Get("OAuthMicrosoftSecret"));

            app.UseTwitterAuthentication(
                consumerKey: ConfigurationManager.AppSettings.Get("OAuthTwitterKey"),
                consumerSecret: ConfigurationManager.AppSettings.Get("OAuthTwitterSecret"));

            app.UseFacebookAuthentication(
                appId: ConfigurationManager.AppSettings.Get("OAuthFacebookKey"),
                appSecret: ConfigurationManager.AppSettings.Get("OAuthFacebookSecret"));

            app.UseGoogleAuthentication();
        }
Example #22
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301883
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            // and also store information about a user logging in with a third party login provider.
            // This is required if your application allows users to login
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            app.UseTwitterAuthentication(
               consumerKey: "PS2yoTd6vf2hcZbbofNUpTUo8",
               consumerSecret: "zxZR1fNgACENr8Q299ZCJcHt4I6K1S6aLxajXyNLI037XoPbUu");

            app.UseFacebookAuthentication(
               appId: "200010180162728",
               appSecret: "780b74301cc8b352137ba107649a3dc6");

            app.UseGoogleAuthentication();
        }
Example #23
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "224714914337263",
               appSecret: "5a1b7152655400fb986d6f817ff19bf6");

            //app.UseGoogleAuthentication();
        }
Example #24
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "880767911941257",
               appSecret: "a4e12738d4bddde8a9f9033a8bc9c626");
            
            app.UseGoogleAuthentication(
        clientId: "592054785953-f0l2eeahhbgf7hpgp9rcdprarsb0gvrh.apps.googleusercontent.com",
        clientSecret: "asPc3j-Q5EkLZVBXEo41B5tr");
        }
Example #25
0
        // 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);

            app.UseFacebookAuthentication(
                ConfigurationManager.AppSettings["FacebookAppId"],
                ConfigurationManager.AppSettings["FacebookAppSecret"]);

            app.UseGoogleAuthentication( new GoogleOAuth2AuthenticationOptions
            {
                ClientId = ConfigurationManager.AppSettings["GoogleClientId"],
                ClientSecret = ConfigurationManager.AppSettings["GoogleClientSecret"],
                CallbackPath = new PathString("/signin-google"),
            });
        }
Example #26
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "dHbf6qruV7RcBg8ZuRuXYIevj",
            //   consumerSecret: "dZY86L1MGf1ddcQmF8RXR4BqRzSZHi5KI9JnRTeRoTPdgVX7Tk");
            //   BackchannelCertificateValidator = new CertificateSubjectKeyIdentifierValidator(
            //    new[]
            //    {
            //        "A5EF0B11CEC04103A34A659048B21CE0572D7D47", // VeriSign Class 3 Secure Server CA - G2
            //        "0D445C165344C1827E1D20AB25F40163D8BE79A5", // VeriSign Class 3 Secure Server CA - G3
            //        "7FD365A7C2DDECBBF03009F34339FA02AF333133", // VeriSign Class 3 Public Primary Certification Authority - G5
            //        "39A55D933676616E73A761DFA16A7E59CDE66FAD" // Symantec Class 3 Secure Server CA - G4
            //    },
            //});
            app.UseFacebookAuthentication(
               appId: "1075945062428240",
               appSecret: "b351502bd4eb2baf08dd12fc8a34578e");

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId = "558261625085-tj9s1uuel2pe73ef673g6dmtbgh8b8r5.apps.googleusercontent.com",
                ClientSecret = "P_Q9Um0xvUgDQ8egE9xzNWXY"
            });
        }
Example #27
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
               appId: "1420357104869015",
               appSecret: "60c31143c17f56f4f29139d50174b999");

            app.UseGoogleAuthentication();
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // 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();
            app.UseFacebookAuthentication(
            appId: "769429839779017",
            appSecret: "910688593eef875bfca0e70767032c0d");
        }
Example #29
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            app.UseMicrosoftAccountAuthentication(
                clientId: "000000004C10DD37",
                clientSecret: "RYELs9crdp8Eebca5YeO0cQQBzbsyGN8");

            app.UseTwitterAuthentication(
               consumerKey: "LHpUEuCYelGiT1zYJrHTDw",
               consumerSecret: "VZnwWxOfzFv9K9FOrfirz2fhD47wgSMo5m41zV3Has");

            app.UseFacebookAuthentication(
               appId: "207117879494713",
               appSecret: "a9496a24c4a27bb5b3ecbb9805306afc");

            app.UseGoogleAuthentication();
        }
Example #30
0
        public void Configuration(IAppBuilder app)
        {
            app.UseOAuthBearerAuthentication(AccountController.OAuthBearerOptions);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            if (IsTrue("ExternalAuth.Facebook.IsEnabled"))
            {
                app.UseFacebookAuthentication(CreateFacebookAuthOptions());
            }

            if (IsTrue("ExternalAuth.Twitter.IsEnabled"))
            {
                app.UseTwitterAuthentication(CreateTwitterAuthOptions());
            }

            if (IsTrue("ExternalAuth.Google.IsEnabled"))
            {
                app.UseGoogleAuthentication(CreateGoogleAuthOptions());
            }
        }
Example #31
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            var options = new FacebookAuthenticationOptions
            {
                AppId        = "1218293774880623",
                AppSecret    = "76d8858819aa61a96f69ea593bddcee0",
                CallbackPath = new PathString("/oauth-redirect/facebook")
            };

            app.UseFacebookAuthentication(options);

            //app.UseFacebookAuthentication(
            //   appId: "520624664798810",
            //   appSecret: "cfc13c337ac561ca07cfaddab431886b");

            //var options = new FacebookAuthenticationOptions
            //{
            //    AppId = "Your App ID",
            //    AppSecret = "Your App Secret",
            //    CallbackPath = new PathString("/oauth-redirect/facebook")
            //};
            //app.UseFacebookAuthentication(options);

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
Example #32
0
        private void ConfigureFacebook(IAppBuilder app)
        {
            const string appId     = "345283286312425";
            const string appSecret = "447e03a0096467eb0b60483c415168d4";
            var          options   = new FacebookAuthenticationOptions
            {
                AppId     = appId,
                AppSecret = appSecret
            };

            options.Scope.Add("email");
            options.Provider = new FacebookAuthenticationProvider()
            {
                OnAuthenticated = async context =>
                {
                    var userDetail = context.User;

                    string id = (dynamic)context.Id;

                    string email       = (dynamic)context.Email;
                    var    userStore   = MembershipTools.NewUserStore();
                    var    userManager = new UserManager <User>(userStore);
                    var    currentUser = userManager.FindByEmail(email);
                    if (currentUser != null)
                    {
                        var serializedUser = context.User;
                        try
                        {
                            currentUser.EmailConfirmed = true;
                            currentUser.Name           = ((dynamic)context.User).first_name.Value;
                            currentUser.Surname        = ((dynamic)context.User).last_name.Value;
                            //currentUser.RegisterDate = DateTime.Now;
                            var avatar = @"https://graph.facebook.com/" + id + "/picture?type=large";

                            var loginInfo = HttpContext.Current.GetOwinContext().Authentication.GetExternalLoginInfo();
                            if (loginInfo != null)
                            {
                                var result = userManager.AddLogin(currentUser.Id, loginInfo.Login);
                            }
                            await userStore.UpdateAsync(currentUser);

                            await userStore.Context.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            string x = ex.StackTrace.ToString();
                        }
                    }
                    else
                    {
                        var user = new User()
                        {
                            Email    = email,
                            Name     = ((dynamic)context.User).first_name.Value,
                            Surname  = ((dynamic)context.User).last_name.Value,
                            UserName = email.Substring(0, email.IndexOf('@'))
                        };
                        userManager.Create(user, StringHelpers.GetCode().Substring(0, 6));
                        var loginInfo = HttpContext.Current.GetOwinContext().Authentication.GetExternalLoginInfo();
                        var result    = userManager.AddLogin(user.Id, loginInfo.Login);
                    }
                }
            };
            app.UseFacebookAuthentication(options);
        }
Example #33
0
        public void ConfigureAuth(IAppBuilder app)
        {
            DataProtectionProvider = app.GetDataProtectionProvider();
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <AppUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromSeconds(0),
                        regenerateIdentity: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie))
                }
            });


            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            //app.UseFacebookAuthentication(
            //   appId: "159579124429445",
            //   appSecret: "8e2368cff3e546eb233bcd3a428e9ab1");

            const string XmlSchemaString   = "http://www.w3.org/2001/XMLSchema#string";
            const string ignoreClaimPrefix = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims";

            if (ConfigurationManager.AppSettings.Get("FacebookAppId").Length > 0)
            {
                var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions()
                {
                    AppId     = ConfigurationManager.AppSettings.Get("FacebookAppId"),
                    AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"),
                    //    BackchannelHttpHandler = new FacebookBackChannelHandler(),
                    //UserInformationEndpoint = "https://graph.facebook.com/v2.4/me?fields=id,name,email,first_name,last_name,location",

                    //Provider = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationProvider()
                    //{
                    //    OnAuthenticated = (context) =>
                    //    {
                    //        context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook"));
                    //        context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:name", context.Name, XmlSchemaString, "Facebook"));
                    //     //   context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:email", context.Email, XmlSchemaString, "Facebook"));
                    //        //var claimType = string.Format("urn:facebook:{0}", claim.Key);
                    //        //try {
                    //        //context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:email", context.Email, XmlSchemaString, "Facebook"));
                    //        //}
                    //        //catch (Exception e)
                    //        //{

                    //        //}
                    //        return Task.FromResult(0);
                    //    }
                    //}
                    Provider = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationProvider()
                    {
                        OnAuthenticated = async context =>
                        {
                            context.Identity.AddClaim(new Claim("urn:facebook:access_token", context.AccessToken));
                            foreach (var claim in context.User)
                            {
                                var    claimType  = string.Format("urn:facebook:{0}", claim.Key);
                                string claimValue = claim.Value.ToString();
                                if (!context.Identity.HasClaim(claimType, claimValue))
                                {
                                    context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook"));
                                }
                            }
                        }
                    }
                    //Provider = new FacebookAuthenticationProvider
                    //{
                    //    OnAuthenticated = async ctx =>
                    //    {
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.DateOfBirth, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.Country, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.Gender, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.MobilePhone, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.OtherPhone, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.HomePhone, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.StateOrProvince, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.Email, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.Country, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.Actor, ctx.User["birthday"].ToString()));
                    //        ctx.Identity.AddClaim(new Claim(ClaimTypes.DateOfBirth, ctx.User["birthday"].ToString()));
                    //    }
                    //}
                };
                facebookOptions.Scope.Add("user_birthday");
                //facebookOptions.Scope.Add("first_name");
                //facebookOptions.Scope.Add("last_name");

                facebookOptions.Scope.Add("user_location");
                facebookOptions.Scope.Add("email");
                app.UseFacebookAuthentication(facebookOptions);
            }

            //app.UseGoogleAuthentication();
        }
Example #34
0
        public void ConfigureOAuth(IAppBuilder app)
        {
            app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);

            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AuthorizeEndpointPath     = new PathString("/api/Account/ExternalLogin"),
                AccessTokenExpireTimeSpan = TimeSpan.FromHours(24),
                Provider             = new SimpleAuthorizationServerProvider(),
                RefreshTokenProvider = new SimpleRefreshTokenProvider()
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);

            KaribouAlpha.DAL.KaribouAlphaContext db = new DAL.KaribouAlphaContext();

            LinkedInAuthClient linkedInAuthClient = db.LinkedInAuthClients.SingleOrDefault(_linked => _linked.Active);

            if (linkedInAuthClient != null)
            {
                ILinkedInAuthenticationProvider providerLnk = new KaribouAlpha.Authentication.LinkedInAuthenticationProvider();
                LinkedInAuthenticationOptions = new LinkedInAuthenticationOptions()
                {
                    ClientId     = linkedInAuthClient.ClientId,
                    ClientSecret = linkedInAuthClient.ClientSecret,
                    Provider     = providerLnk,
                    CallbackPath = new PathString("/AuthCallBack."),
                    Scope        = { "r_basicprofile", "r_emailaddress" },
                    //BackchannelHttpHandler = new LinkedInBackChannelHandler()
                };
            }
            //http://www.c-sharpcorner.com/article/implementing-oauth2-0-authorization-for-google-in-asp-net/
            //https://developers.google.com/actions/identity/oauth2-code-flow

            GoogleAuthClient googleClient = db.GoogleAuthClients.SingleOrDefault(_google => _google.Active);

            if (googleClient != null)
            {
                GoogleAuthProvider gProvider = new GoogleAuthProvider();
                googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
                {
                    ClientId     = googleClient.ClientId,
                    ClientSecret = googleClient.ClientSecret,
                    Provider     = gProvider
                };
            }

            KaribouAlpha.Models.FaceBookClient clientFb = db.FaceBookClients.SingleOrDefault(_fb => _fb.Active);
            if (clientFb != null)
            {
                var fbProvider          = new FacebookAuthProvider();
                var facebookAuthOptions = new FacebookAuthenticationOptions()
                {
                    AppId     = clientFb.AppId,
                    AppSecret = clientFb.AppSecret,
                    Provider  = fbProvider,
                };
                app.UseFacebookAuthentication(facebookAuthOptions);
            }
        }
Example #35
0
        public static void Configuration(IAppBuilder app)
        {
            //app.Use<DebugMiddleware>();
            app.UseDebugMiddleware(new DebugMiddlewareOptions
            {
                OnIncomingRequest = (ctx) =>
                {
                    var watch = new Stopwatch();
                    watch.Start();
                    ctx.Environment["DebugStopwatch"] = watch;
                },
                OnOutgoingRequest = (ctx) =>
                {
                    var watch = (Stopwatch)ctx.Environment["DebugStopwatch"];
                    watch.Stop();
                    Debug.WriteLine($"Request took: {watch.ElapsedMilliseconds}");
                }
            });
            //app.Use<DebugMiddleware>(new DebugMiddlewareOptions
            //{
            //    OnIncomingRequest = (ctx) =>
            //    {
            //        var watch = new Stopwatch();
            //        watch.Start();
            //        ctx.Environment["DebugStopwatch"] = watch;
            //    },
            //    OnOutgoingRequest = (ctx) => {
            //        var watch = (Stopwatch)ctx.Environment["DebugStopwatch"];
            //        watch.Stop();
            //        Debug.WriteLine($"Request took: {watch.ElapsedMilliseconds}");
            //    }

            //});
            //app.Use(async (ctx, next) => {
            //    Debug.WriteLine($"Incoming Request :{ctx.Request.Path}");
            //    await next();
            //    Debug.WriteLine($"Outgoing Request :{ctx.Request.Path}");
            //});
            //app.Map("/nancy", mappedApp => { mappedApp.UseNancy(); });

            app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
            {
                AuthenticationType = "ApplicaitonCookie",
                LoginPath          = new Microsoft.Owin.PathString("/Auth/Login")
            });

            app.UseFacebookAuthentication(new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions
            {
                AppId     = "979980915517227",
                AppSecret = "0d9a048db49c47e9e2c9f126a84247aa",
                SignInAsAuthenticationType      = "ApplicationCookie",
                BackchannelCertificateValidator = null
            });

            //app.UseTwitterAuthentication(new Microsoft.Owin.Security.Twitter.TwitterAuthenticationOptions
            //{
            //    ConsumerKey = "",
            //    ConsumerSecret = "",
            //    AuthenticationType = "ApplicationCookie",
            //    BackchannelCertificateValidator = null
            //});

            app.Use(async(ctx, next) =>
            {
                if (ctx.Authentication.User.Identity.IsAuthenticated)
                {
                    Debug.WriteLine($"User: {ctx.Authentication.User.Identity.Name}");
                }
                else
                {
                    Debug.WriteLine("User Not Authenticated");
                }
                await next();
            });

            var configApi = new HttpConfiguration();

            configApi.MapHttpAttributeRoutes();
            app.UseWebApi(configApi);
            app.Map("/nancy", mappedApp => { mappedApp.UseNancy(); });
            //app.UseNancy(config => {
            //    config.PassThroughWhenStatusCodesAre(HttpStatusCode.NotFound);
            //});

            //app.Use(async (ctx, next) =>
            //{
            //    await ctx.Response.WriteAsync("Hello World");
            //});
        }
Example #36
0
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(MyDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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("/Accounts/Login"),
                //    Provider = new CookieAuthenticationProvider
                //    {
                //        // Enables the application to validate the security stamp when the user logs in.
                //        // This is a security feature which is used when you change a password or add an external login to your account.
                //        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                //            validateInterval: TimeSpan.FromMinutes(30),
                //            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                //    }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            //// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            //// Enables the application to remember the second login verification factor such as phone or email.
            //// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            //// This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            //// 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 = "",
            //    ClientSecret = ""
            //});

            // on web facebook
            app.UseFacebookAuthentication(
                appId: "923045878132923",
                appSecret: "3b6cf2034bdaf43e7c73f0e81b0bd3ee");

            // localhost Facebook
            //app.UseFacebookAuthentication(
            //   appId: "2499932460279194",
            //   appSecret: "acecd01381f9c19070525c82ec3a04bf");

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "218795749125-dipvu2kgf66jgb6e7er0tqle2of09kml.apps.googleusercontent.com",
                ClientSecret = "T7dFRZfOWKZe1fOy1zMKUTX9"
            });
        }
        public static void ConfigureIdentityProviders(IAppBuilder app, string signInAsType)
        {
            var google = new GoogleOAuth2AuthenticationOptions
            {
                AuthenticationType         = "Google",
                Caption                    = "Google",
                SignInAsAuthenticationType = signInAsType,

                ClientId     = "767400843187-8boio83mb57ruogr9af9ut09fkg56b27.apps.googleusercontent.com",
                ClientSecret = "5fWcBT0udKY7_b6E3gEiJlze"
            };

            app.UseGoogleAuthentication(google);

            var fb = new FacebookAuthenticationOptions
            {
                AuthenticationType         = "Facebook",
                Caption                    = "Facebook",
                SignInAsAuthenticationType = signInAsType,

                AppId     = "676607329068058",
                AppSecret = "9d6ab75f921942e61fb43a9b1fc25c63"
            };

            app.UseFacebookAuthentication(fb);

            var twitter = new TwitterAuthenticationOptions
            {
                AuthenticationType         = "Twitter",
                Caption                    = "Twitter",
                SignInAsAuthenticationType = signInAsType,

                ConsumerKey    = "N8r8w7PIepwtZZwtH066kMlmq",
                ConsumerSecret = "df15L2x6kNI50E4PYcHS0ImBQlcGIt6huET8gQN41VFpUCwNjM"
            };

            app.UseTwitterAuthentication(twitter);

            var adfs = new WsFederationAuthenticationOptions
            {
                AuthenticationType         = "adfs",
                Caption                    = "ADFS",
                SignInAsAuthenticationType = signInAsType,

                MetadataAddress = "https://adfs.leastprivilege.vm/federationmetadata/2007-06/federationmetadata.xml",
                Wtrealm         = "urn:idsrv3"
            };

            app.UseWsFederationAuthentication(adfs);

            var aad = new OpenIdConnectAuthenticationOptions
            {
                AuthenticationType         = "aad",
                Caption                    = "Azure AD",
                SignInAsAuthenticationType = signInAsType,

                Authority   = "https://login.windows.net/4ca9cb4c-5e5f-4be9-b700-c532992a3705",
                ClientId    = "65bbbda8-8b85-4c9d-81e9-1502330aacba",
                RedirectUri = "https://localhost:44333/core/aadcb"
            };

            app.UseOpenIdConnectAuthentication(aad);
        }
Example #38
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(MmmContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, User>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");
            #region LinkedIn

            var linkedinAuthenticationOptions = new LinkedInAuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["LinkedinClientId"],
                ClientSecret = ConfigurationManager.AppSettings["LinkedinClientSecretKey"],
            };

            //linkedinAuthenticationOptions.Scope.Add("r_basicprofile");
            //linkedinAuthenticationOptions.Scope.Add("r_emailaddress");

            app.UseLinkedInAuthentication(linkedinAuthenticationOptions);
            #endregion

            #region Facebook

            //app.UseFacebookAuthentication(
            //   appId: "",
            //   appSecret: "");

            var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
            {
                AppId     = ConfigurationManager.AppSettings["FacebookAppId"],
                AppSecret = ConfigurationManager.AppSettings["FacebookAppSecretKey"],
                BackchannelHttpHandler = new FacebookBackChannelHandler(),
                //UserInformationEndpoint = "https://graph.facebook.com/v2.4/me?fields=id,email"
                UserInformationEndpoint = "https://graph.facebook.com/v2.4/me?fields=id,name,first_name,last_name,email"
            };

            facebookAuthenticationOptions.Scope.Add("email");
            facebookAuthenticationOptions.Scope.Add("public_profile");

            app.UseFacebookAuthentication(facebookAuthenticationOptions);
            #endregion

            #region Google

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});

            var googleAuthenticationOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["GoogleClientId"],
                ClientSecret = ConfigurationManager.AppSettings["GoogleClientSecretKey"],
                Provider     = new GoogleOAuth2AuthenticationProvider()
                {
                    OnAuthenticated = async context =>
                    {
                        context.Identity.AddClaim(new Claim("GoogleAccessToken", context.AccessToken));
                        foreach (var claim in context.User)
                        {
                            var    claimType  = string.Format("urn:google:{0}", claim.Key);
                            string claimValue = claim.Value.ToString();
                            if (!context.Identity.HasClaim(claimType, claimValue))
                            {
                                context.Identity.AddClaim(new Claim(claimType, claimValue, "XmlSchemaString", "Google"));
                            }
                        }
                    }
                }
            };

            googleAuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/plus.login email");
            googleAuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/plus.login profile");

            app.UseGoogleAuthentication(googleAuthenticationOptions);
            #endregion
        }
Example #39
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            app.UseTwitterAuthentication(new TwitterAuthenticationOptions
            {
                ConsumerKey    = "xePhcLss7uZQVFSUEhJlBQf8d",
                ConsumerSecret = "q7nNNhZBn3Evbm4o8qcWobmgY62VaP72TGklzObnbS0VsTD7op",
                BackchannelCertificateValidator = new Microsoft.Owin.Security.CertificateSubjectKeyIdentifierValidator(new[]
                {
                    "A5EF0B11CEC04103A34A659048B21CE0572D7D47",  // VeriSign Class 3 Secure Server CA - G2
                    "0D445C165344C1827E1D20AB25F40163D8BE79A5",  // VeriSign Class 3 Secure Server CA - G3
                    "7FD365A7C2DDECBBF03009F34339FA02AF333133",  // VeriSign Class 3 Public Primary Certification Authority - G5
                    "39A55D933676616E73A761DFA16A7E59CDE66FAD",  // Symantec Class 3 Secure Server CA - G4
                    "‎add53f6680fe66e383cbac3e60922e3b4c412bed", // Symantec Class 3 EV SSL CA - G3
                    "4eb6d578499b1ccf5f581ead56be3d9b6744a5e5",  // VeriSign Class 3 Primary CA - G5
                    "5168FF90AF0207753CCCD9656462A212B859723B",  // DigiCert SHA2 High Assurance Server C‎A
                    "B13EC36903F8BF4701D498261A0802EF63642BC3"   // DigiCert High Assurance EV Root CA
                })
            });

            app.UseFacebookAuthentication(
                appId: "784464008384576",
                appSecret: "647d25e957e276bc6888ec32376355d1");

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "392503782225-2qtjk5ji2lkgnced2s9f39q9fl66d85h.apps.googleusercontent.com",
                ClientSecret = "jthVZYL4z1ZuMgUKYJTO-AVJ"
            });
        }
Example #40
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(GroceryDbContext.Create);

            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create);
            app.CreatePerOwinContext <UserManager <ApplicationUser> >(CreateManager); // CreatePerOwinContext để quản lý user manager (giảm phụ thuộc service và application)

            //authen token cho admin API
            app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath         = new PathString("/oauth/token"), //tất cả đường dẫn đều thông qua cái này
                Provider                  = new AuthorizationServerProvider(),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                AllowInsecureHttp         = true,
            });
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            // cấu hình đăng nhập bằng  cookie MVC
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/dang-nhap.html"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Cho phép ứng dụng xác thực tem bảo mật khi người dùng đăng nhập.

                    /* Đây là một tính năng bảo mật được sử dụng khi bạn thay đổi mật khẩu
                     * hoặc thêm thông tin đăng nhập bên ngoài vào tài khoản của mình. */
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager, DefaultAuthenticationTypes.ApplicationCookie))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
                appId: "2937019933289875",
                appSecret: "16fa22b6da5a85ec2414c61016338d87");

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "302641436335-dkmpnuts0eokr1rcffg9b3lauevrtp2f.apps.googleusercontent.com",
                ClientSecret = "60-Tuyxfd2POIzGMGptE273p"
            });
        }
Example #41
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // 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: "");


            var facebookOption = new FacebookAuthenticationOptions()
            {
                AppId     = "1514030938675629",
                AppSecret = "67eb0fe6b93bdcd7d847a08913dce902",
                BackchannelHttpHandler = new FacebookBackChannelHandler(),

                Provider = new FacebookAuthenticationProvider
                {
                    OnAuthenticated = context =>
                    {
                        context.Identity.AddClaim(new Claim("urn:facebook:email", context.Email));
                        context.Identity.AddClaim(new Claim("FacebookAccessToken", context.AccessToken)); // user acces token needed for posting on the wall
                        return(Task.FromResult(true));
                    }
                },
                SignInAsAuthenticationType = Microsoft.Owin.Security.AppBuilderSecurityExtensions.GetDefaultSignInAsAuthenticationType(app),
                UserInformationEndpoint    = "https://graph.facebook.com/v2.10/me?fields=id,name,email,first_name,last_name"
                                             // UserInformationEndpoint = "https://graph.facebook.com/v2.10/me?fields=email"
            };

            facebookOption.Scope.Add("email");
            facebookOption.Scope.Add("public_profile");
            //facebookOption.Scope.Add("publish_actions"); // permission needed for posting on the wall
            //facebookOption.Scope.Add("publish_pages"); // permission needed for posting on the page
            app.UseFacebookAuthentication(facebookOption);

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
        public void Configuration(IAppBuilder app)
        {
            // AutoFac config
            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.Register(c => new AppointsDbContext("AppointsDb"));
            builder.Register(c => new JwtSecurityTokenHandler());
            var container = builder.Build();

            var config = new HttpConfiguration();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            // CORS
            var allowedOriginsString = ConfigurationManager.AppSettings["cors:AllowedOrigins"];

            if (!String.IsNullOrEmpty(allowedOriginsString))
            {
                var corsPolicy = new CorsPolicy
                {
                    AllowAnyHeader      = true,
                    AllowAnyMethod      = true,
                    SupportsCredentials = true
                };
                var allowedOrigins = allowedOriginsString.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var allowedOrigin in allowedOrigins)
                {
                    corsPolicy.Origins.Add(allowedOrigin);
                }
                app.UseCors(new CorsOptions
                {
                    PolicyProvider = new CorsPolicyProvider
                    {
                        PolicyResolver = context => Task.FromResult(corsPolicy)
                    }
                });
            }

            // Authentication/Authorization
            var issuer   = ConfigurationManager.AppSettings["jwt:Issuer"];
            var audience = ConfigurationManager.AppSettings["jwt:Audience"];
            var secret   = ConfigurationManager.AppSettings["jwt:SecretKey"];

            // Default JWT token based authorization
            app.UseJwtBearerAuthentication(
                new JwtBearerAuthenticationOptions
            {
                AuthenticationMode           = AuthenticationMode.Active,
                AllowedAudiences             = new[] { audience },
                IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
                {
                    new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
                }
            });

            // Required for 3rd-party login flow.
            var externalCookie = new CookieAuthenticationOptions
            {
                AuthenticationType = "ExternalCookie",
                AuthenticationMode = AuthenticationMode.Passive
            };

            app.UseCookieAuthentication(externalCookie);

            app.UseFacebookAuthentication(new FacebookAuthenticationOptions
            {
                AppId                      = ConfigurationManager.AppSettings["facebook:AppId"],
                AppSecret                  = ConfigurationManager.AppSettings["facebook:AppSecret"],
                AuthenticationType         = "facebook",
                AuthenticationMode         = AuthenticationMode.Passive,
                SignInAsAuthenticationType = "ExternalCookie"
            });
            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
            {
                ClientId                   = ConfigurationManager.AppSettings["google:ClientId"],
                ClientSecret               = ConfigurationManager.AppSettings["google:ClientSecret"],
                AuthenticationType         = "google",
                AuthenticationMode         = AuthenticationMode.Passive,
                SignInAsAuthenticationType = "ExternalCookie"
            });

            WebApiConfig.Register(config);
            app.UseWebApi(config);
        }
Example #43
0
        // For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            //Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
            //SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
            //int timeout = (int)section.Timeout.TotalMinutes;

            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
            #region Logged in Permanentely until logout manually
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            #endregion

            #region Logout on session TimeOut
            //app.UseCookieAuthentication(new CookieAuthenticationOptions
            //{
            //    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            //    LoginPath = new PathString("/Account/Login"),
            //    Provider = new CookieAuthenticationProvider
            //    {
            //        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
            //        validateInterval: TimeSpan.FromMinutes(timeout),
            //        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
            //    },
            //    SlidingExpiration = false,
            //    ExpireTimeSpan = TimeSpan.FromMinutes(timeout)
            //});
            #endregion
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            app.UseFacebookAuthentication(
                appId: "1816549368403318",
                appSecret: "c2c2aeed174754a55e9632ff443ad2f8");

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "710129204797-5u7f439nav7j5bjpu207d19diprk40do.apps.googleusercontent.com",
                ClientSecret = "QeFKkfYb4GOXRY9M-5J3hPSd"
            });
        }
Example #44
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            app.UseMicrosoftAccountAuthentication(
                clientId: "68f815c8-6cae-4d25-bb7e-a5cc2776bdb8",
                clientSecret: "YNu5Po3JzY39m8YfU0d6Oht");

            app.UseTwitterAuthentication(new TwitterAuthenticationOptions
            {
                ConsumerKey    = "8WC3vDdvQVEmw8j8wnjn2TDSP",
                ConsumerSecret = "Vj9ansEijesYOTqgj2RmGLuRdqr45RlZiqbTd2SbvDkqTuKA9y",
                BackchannelCertificateValidator = new CertificateSubjectKeyIdentifierValidator(new[]
                {
                    "A5EF0B11CEC04103A34A659048B21CE0572D7D47", // VeriSign Class 3 Secure Server CA - G2
                    "0D445C165344C1827E1D20AB25F40163D8BE79A5", // VeriSign Class 3 Secure Server CA - G3
                    "7FD365A7C2DDECBBF03009F34339FA02AF333133", // VeriSign Class 3 Public Primary Certification Authority - G5
                    "39A55D933676616E73A761DFA16A7E59CDE66FAD", // Symantec Class 3 Secure Server CA - G4
                    "5168FF90AF0207753CCCD9656462A212B859723B", //DigiCert SHA2 High Assurance Server C‎A
                    "B13EC36903F8BF4701D498261A0802EF63642BC3"  //DigiCert High Assurance EV Root CA
                })
            });

            app.UseFacebookAuthentication(
                appId: "646944302145879",
                appSecret: "62504ea62d9a5909a8915215cdbfaa9e");

            app.UseGoogleAuthentication(
                clientId: "652994850001-bgshjqiponr09o75jjrfebbjh7kbiruh.apps.googleusercontent.com",
                clientSecret: "yqBA65jCHS4T6dtE-WFfNtF7"
                );
        }
Example #45
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            var fbAuthOpts = new FacebookAuthenticationOptions();

            fbAuthOpts.Scope.Add("email");
            fbAuthOpts.Scope.Add("user_friends");
            fbAuthOpts.Scope.Add("user_likes");
            fbAuthOpts.Scope.Add("publish_actions");

            fbAuthOpts.AppId     = "1620058294677789";
            fbAuthOpts.AppSecret = "3b56df655768017dcd61b2423e107686";
            fbAuthOpts.Provider  = new FacebookAuthenticationProvider()
            {
                OnAuthenticated = async context =>
                {
                    context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
                }
            };

            app.UseFacebookAuthentication(fbAuthOpts);

            //app.UseFacebookAuthentication(
            //   appId: "368452513336704",
            //   appSecret: "5e4dfa01d3ff3565d481b697b24a2815");

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
Example #46
0
        // Per altre informazioni su come configurare l'autenticazione, vedere https://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configurare il contesto di database, la gestione utenti e la gestione accessi in modo da usare un'unica istanza per richiesta
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create);

            // Consentire all'applicazione di utilizzare un cookie per memorizzare informazioni relative all'utente connesso
            // e per memorizzare temporaneamente le informazioni relative a un utente che accede tramite un provider di accesso di terze parti
            // Configurare il cookie di accesso
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Consente all'applicazione di convalidare l'indicatore di sicurezza quando l'utente esegue l'accesso.
                    // Questa funzionalità di sicurezza è utile quando si cambia una password o si aggiungono i dati di un account di accesso esterno all'account personale.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser, long>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
                        getUserIdCallback: (id) => (id.GetUserId <long>()))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Consente all'applicazione di memorizzare temporaneamente le informazioni dell'utente durante la verifica del secondo fattore nel processo di autenticazione a due fattori.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Consente all'applicazione di memorizzare il secondo fattore di verifica dell'accesso, ad esempio il numero di telefono o l'indirizzo e-mail.
            // Una volta selezionata questa opzione, il secondo passaggio di verifica durante la procedura di accesso viene memorizzato sul dispositivo usato per accedere.
            // È simile all'opzione RememberMe disponibile durante l'accesso.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Rimuovere il commento dalle seguenti righe per abilitare l'accesso con provider di accesso di terze parti
            app.UseMicrosoftAccountAuthentication(
                clientId: "xxxxxxxxxxxxxxxxxx",
                clientSecret: "xxxxxxxxxxxxxxxxxx");


            app.UseTwitterAuthentication(
                consumerKey: "xxxxxxxxxxxxxxxxxx",
                consumerSecret: "xxxxxxxxxxxxxxxxxx");

            var facebookOptions = new FacebookAuthenticationOptions
            {
                AppId     = "xxxxxxxxxxxxxxxxxx",
                AppSecret = "xxxxxxxxxxxxxxxxxx",
                //BackchannelHttpHandler = new FacebookBackChannelHandler(),
                UserInformationEndpoint = "https://graph.facebook.com/v2.11/me?fields=id,email,picture",
                Provider = new FacebookAuthenticationProvider()
                {
                    OnAuthenticated = (context) =>
                    {
                        context.Identity.AddClaim(new Claim("urn:facebook:access_token", context.AccessToken, ClaimValueTypes.String, "Facebook"));
                        context.Identity.AddClaim(new Claim("urn:facebook:email", context.Email, ClaimValueTypes.Email, "Facebook"));
                        return(Task.FromResult(0));
                    }
                },
            };

            facebookOptions.Scope.Add("email");
            facebookOptions.Scope.Add("user_friends");
            //facebookOptions.Scope.Add("friends_about_me");
            //facebookOptions.Scope.Add("friends_photos");
            app.UseFacebookAuthentication(facebookOptions);

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "xxxxxxxxxxxxxxxxxx",
                ClientSecret = "xxxxxxxxxxxxxxxxxx"
            });

            var linkedInOptions = new LinkedInAuthenticationOptions
            {
                ClientId     = "xxxxxxxxxxxxxxxxxx",
                ClientSecret = "xxxxxxxxxxxxxxxxxx",
                Provider     = new LinkedInAuthenticationProvider()
                {
                    OnAuthenticated = (context) =>
                    {
                        context.Identity.AddClaim(new Claim("urn:linkedin:accesstoken", context.AccessToken, ClaimValueTypes.String, "LinkedIn"));
                        context.Identity.AddClaim(new Claim("urn:linkedin:name", context.Name));
                        context.Identity.AddClaim(new Claim("urn:linkedin:email", context.Email, ClaimValueTypes.Email, "LinkedIn"));
                        context.Identity.AddClaim(new Claim("urn:linkedin:id", context.Id));
                        return(Task.FromResult(0));
                    }
                },
            };

            app.UseLinkedInAuthentication(linkedInOptions);


            //app.UseYahooAuthentication("", "");

            //app.UseInstagramInAuthentication("", "");

            //var options = new GooglePlusAuthenticationOptions
            //{
            //    ClientId = "",
            //    ClientSecret = "",
            //    RequestOfflineAccess = true,
            //    Provider = new GooglePlusAuthenticationProvider
            //    {
            //        OnAuthenticated = async context => System.Diagnostics.Debug.WriteLine(String.Format("Refresh Token: {0}", context.RefreshToken))
            //    }
            //};
            //options.MomentTypes.Add("http://schemas.google.com/AddActivity");
            //options.MomentTypes.Add("http://schemas.google.com/CheckInActivity");
            //options.MomentTypes.Add("http://schemas.google.com/BuyActivity");
            //app.UseGooglePlusAuthentication(options);

            //app.UseOpenIDAuthentication("http://me.yahoo.com/", "Yahoo");

            //app.UseOpenIDAuthentication("https://www.google.com/accounts/o8/id", "Google");

            //app.UseDropboxAuthentication(
            //    appKey: "",
            //    appSecret: "");

            //app.UseFoursquareAuthentication(
            //	clientId: "",
            //	clientSecret: "");

            //app.UseFlickrAuthentication("", "");

            //app.UseSpotifyAuthentication(
            //    clientId: "",
            //    clientSecret: "");
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(SoLoudContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create);

            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(20),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Token Generation
            app.UseOAuthBearerTokens(OAuthOptions);
            //app.UseOAuthAuthorizationServer(OAuthOptions);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");
            var a = new TwitterAuthenticationOptions
            {
                ConsumerKey    = "R8RxlH7tsQJD56fy0WTYNbUkd",
                ConsumerSecret = "Srpbyv1vVtyiWZx4ireJAie5ptXAN7BoDycTWbyaMpy3rs5P87",
                Provider       = new Microsoft.Owin.Security.Twitter.TwitterAuthenticationProvider
                {
                    OnAuthenticated = (context) =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("urn:twitter:access_token", context.AccessToken));
                        context.Identity.AddClaim(new System.Security.Claims.Claim("urn:twitter:access_secret", context.AccessTokenSecret));
                        return(Task.FromResult(0));
                    }
                },
                BackchannelCertificateValidator = new Microsoft.Owin.Security.CertificateSubjectKeyIdentifierValidator(new[]
                {
                    "A5EF0B11CEC04103A34A659048B21CE0572D7D47",  // VeriSign Class 3 Secure Server CA - G2
                    "0D445C165344C1827E1D20AB25F40163D8BE79A5",  // VeriSign Class 3 Secure Server CA - G3
                    "7FD365A7C2DDECBBF03009F34339FA02AF333133",  // VeriSign Class 3 Public Primary Certification Authority - G5
                    "39A55D933676616E73A761DFA16A7E59CDE66FAD",  // Symantec Class 3 Secure Server CA - G4
                    "‎add53f6680fe66e383cbac3e60922e3b4c412bed", // Symantec Class 3 EV SSL CA - G3
                    "4eb6d578499b1ccf5f581ead56be3d9b6744a5e5",  // VeriSign Class 3 Primary CA - G5
                    "5168FF90AF0207753CCCD9656462A212B859723B",  // DigiCert SHA2 High Assurance Server C‎A
                    "B13EC36903F8BF4701D498261A0802EF63642BC3"   // DigiCert High Assurance EV Root CA
                })
            };

            app.UseTwitterAuthentication(a);

            app.UseFacebookAuthentication(new FacebookAuthenticationOptions()
            {
                AppId     = "1625319744433880",
                AppSecret = "78d4e778fac962e865fd487e5872dab2",
                BackchannelHttpHandler  = new FacebookBackChannelHandler(),
                UserInformationEndpoint = "https://graph.facebook.com/v2.4/me?fields=id,name,email,first_name,last_name",
                Scope    = { "email", "public_profile", "publish_actions", "user_posts" },
                Provider = new FacebookAuthenticationProvider()
                {
                    OnAuthenticated = (context) =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim(SoloudClaimTypes.FacebookAccessToken.ToString(), context.AccessToken, ClaimValueTypes.String, "Facebook"));

                        return(Task.FromResult(0));
                    }
                }
            });

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
Example #48
0
        private static void ConfigureLoginProviders(IAppBuilder app)
        {
            var loginProviders = new ConfigurationLoginProviders();

            if (!string.IsNullOrEmpty(clientId))
            {
                app.UseOpenIdConnectAuthentication(
                    new OpenIdConnectAuthenticationOptions
                {
                    ClientId              = clientId,
                    Authority             = authority,
                    PostLogoutRedirectUri = postLogoutRedirectUri,
                    Notifications         = new OpenIdConnectAuthenticationNotifications
                    {
                        AuthenticationFailed = context =>
                        {
                            context.HandleResponse();
                            context.Response.Redirect("/Error?message=" + context.Exception.Message);
                            return(Task.FromResult(0));
                        }
                    }
                });
            }



            if (loginProviders.Facebook.Use)
            {
                app.UseFacebookAuthentication(new FacebookAuthenticationOptions
                {
                    AppId     = loginProviders.Facebook.Key,
                    AppSecret = loginProviders.Facebook.Secret
                });
            }

            if (loginProviders.Google.Use)
            {
                app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
                {
                    ClientId     = loginProviders.Google.Key,
                    ClientSecret = loginProviders.Google.Secret
                });
            }

            if (loginProviders.Twitter.Use)
            {
                app.UseTwitterAuthentication(new TwitterAuthenticationOptions
                {
                    ConsumerKey    = loginProviders.Twitter.Key,
                    ConsumerSecret = loginProviders.Twitter.Secret
                });
            }

            if (loginProviders.Microsoft.Use)
            {
                app.UseMicrosoftAccountAuthentication(new MicrosoftAccountAuthenticationOptions
                {
                    ClientId     = loginProviders.Microsoft.Key,
                    ClientSecret = loginProviders.Microsoft.Secret
                });
            }
        }
Example #49
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            app.UseMicrosoftAccountAuthentication(
                clientId: System.Configuration.ConfigurationManager.AppSettings["MicrosoftOAuthClientID"],
                clientSecret: System.Configuration.ConfigurationManager.AppSettings["MicrosoftOAuthClientSecret"]);

            //TODO: Fix issues with Microsoft Authentication, commented out as not working currently: Investigate
            //app.UseMicrosoftAccountAuthentication(new Microsoft.Owin.Security.MicrosoftAccount.MicrosoftAccountAuthenticationOptions
            //{
            //    ClientId = System.Configuration.ConfigurationManager.AppSettings["MicrosoftOAuthClientID"],
            //    ClientSecret = System.Configuration.ConfigurationManager.AppSettings["MicrosoftOAuthClientSecret"],
            //    CallbackPath = new PathString("/signin-microsoft"),
            //    AuthenticationType = "Microsoft",
            //    AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive,
            //    Caption = "This is the caption"
            //});

            // TODO: Twitter and Facebook not currently returning a email address (Was working: why is this happening???)
            app.UseTwitterAuthentication(new TwitterAuthenticationOptions
            {
                ConsumerKey    = System.Configuration.ConfigurationManager.AppSettings["TwitterOAuthConsumerKey"],
                ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["TwitterOAuthConsumerSecret"],
                BackchannelCertificateValidator = null
            });

            app.UseFacebookAuthentication(
                appId: System.Configuration.ConfigurationManager.AppSettings["FacebookOAuthAppID"],
                appSecret: System.Configuration.ConfigurationManager.AppSettings["FacebookOAuthClientSecret"]);

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = System.Configuration.ConfigurationManager.AppSettings["GoogleOAuthClientID"],
                ClientSecret = System.Configuration.ConfigurationManager.AppSettings["GoogleOAuthClientSecret"]
            });
        }
Example #50
0
        public void Configuration(IAppBuilder app)
        {
            var logger = app.CreateLogger("Katana.Sandbox.WebServer");

            logger.WriteInformation("Application Started");

            app.UseErrorPage(Microsoft.Owin.Diagnostics.ErrorPageOptions.ShowAll);

            app.Use(async(context, next) =>
            {
                context.Get <TextWriter>("host.TraceOutput").WriteLine("{0} {1}{2}", context.Request.Method, context.Request.PathBase, context.Request.Path);
                await next();
                context.Get <TextWriter>("host.TraceOutput").WriteLine("{0} {1}{2}", context.Response.StatusCode, context.Request.PathBase, context.Request.Path);
            });

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Application",
                // LoginPath = new PathString("/Account/Login"),
            });

            app.SetDefaultSignInAsAuthenticationType("External");

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "External",
                AuthenticationMode = AuthenticationMode.Active,
                CookieName         = CookieAuthenticationDefaults.CookiePrefix + "External",
                ExpireTimeSpan     = TimeSpan.FromMinutes(5),
                CookieManager      = new SystemWebChunkingCookieManager()
            });

            // https://developers.facebook.com/apps/
            app.UseFacebookAuthentication(new FacebookAuthenticationOptions
            {
                AppId         = Environment.GetEnvironmentVariable("facebook:appid"),
                AppSecret     = Environment.GetEnvironmentVariable("facebook:appsecret"),
                Scope         = { "email" },
                Fields        = { "name", "email" },
                CookieManager = new SystemWebCookieManager()
            });

            // https://console.developers.google.com/apis/credentials
            // https://developers.google.com/identity/protocols/OAuth2WebServer
            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = Environment.GetEnvironmentVariable("google:clientid"),
                ClientSecret = Environment.GetEnvironmentVariable("google:clientsecret"),
            });

            //// Flow to get user identifier in OpenID for migration to OAuth 2.0
            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "448955186993-2vmtajdpl41ipktlg809780c0craq88e.apps.googleusercontent.com",
            //    ClientSecret = "Ngdb_GRmO3X2pC3WVt73Rod0",
            //    Provider = new GoogleOAuth2AuthenticationProvider()
            //    {
            //        OnApplyRedirect = context =>
            //        {
            //            // Add openid realm to get openid identifier in token response
            //            context.Response.Redirect(context.RedirectUri + "&openid.realm=http://localhost:49222/");
            //        },

            //        OnAuthenticated = context =>
            //        {
            //            var idToken = context.TokenResponse.Value<string>("id_token");
            //            var jwtIdToken = new JwtSecurityToken(idToken);
            //            var claims = jwtIdToken.Claims;

            //            var openid_id = claims.FirstOrDefault(x => x.Type.Equals("openid_id", StringComparison.CurrentCulture));
            //            return Task.FromResult(0);
            //        }
            //    }
            //});

            // https://apps.twitter.com/
            // https://dev.twitter.com/web/sign-in/implementing
            app.UseTwitterAuthentication(Environment.GetEnvironmentVariable("twitter:consumerkey"), Environment.GetEnvironmentVariable("twitter:consumersecret"));

            // https://azure.microsoft.com/en-us/documentation/articles/active-directory-v2-app-registration/
            app.UseMicrosoftAccountAuthentication(Environment.GetEnvironmentVariable("microsoftaccount:clientid"), Environment.GetEnvironmentVariable("microsoftaccount:clientsecret"));

            // app.UseAspNetAuthSession();

            /*
             * app.UseCookieAuthentication(new CookieAuthenticationOptions()
             * {
             *  SessionStore = new InMemoryAuthSessionStore()
             * });
             * app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
             */

            app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions()
            {
                Wtrealm         = "https://tratcheroutlook.onmicrosoft.com/AspNetCoreSample",
                MetadataAddress = "https://login.windows.net/cdc690f9-b6b8-4023-813a-bae7143d1f87/FederationMetadata/2007-06/FederationMetadata.xml",
            });

            app.UseOpenIdConnectAuthentication(new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions()
            {
                Authority     = Environment.GetEnvironmentVariable("oidc:authority"),
                ClientId      = Environment.GetEnvironmentVariable("oidc:clientid"),
                RedirectUri   = "https://localhost:44318/",
                CookieManager = new SystemWebCookieManager()
            });

            /*
             * app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
             * {
             * });
             *
             * // CORS support
             * app.Use(async (context, next) =>
             * {
             *  IOwinRequest req = context.Request;
             *  IOwinResponse res = context.Response;
             *  // for auth2 token requests, and web api requests
             *  if (req.Path.StartsWithSegments(new PathString("/Token")) ||
             *      req.Path.StartsWithSegments(new PathString("/api")))
             *  {
             *      // if there is an origin header
             *      var origin = req.Headers.Get("Origin");
             *      if (!string.IsNullOrEmpty(origin))
             *      {
             *          // allow the cross-site request
             *          res.Headers.Set("Access-Control-Allow-Origin", origin);
             *      }
             *
             *      // if this is pre-flight request
             *      if (req.Method == "OPTIONS")
             *      {
             *          // respond immediately with allowed request methods and headers
             *          res.StatusCode = 200;
             *          res.Headers.AppendCommaSeparatedValues("Access-Control-Allow-Methods", "GET", "POST");
             *          res.Headers.AppendCommaSeparatedValues("Access-Control-Allow-Headers", "authorization");
             *          // no further processing
             *          return;
             *      }
             *  }
             *  // continue executing pipeline
             *  await next();
             * });
             *
             * app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
             * {
             *  AuthorizeEndpointPath = new PathString("/Authorize"),
             *  TokenEndpointPath = new PathString("/Token"),
             *  ApplicationCanDisplayErrors = true,
             #if DEBUG
             *  AllowInsecureHttp = true,
             #endif
             *  Provider = new OAuthAuthorizationServerProvider
             *  {
             *      OnValidateClientRedirectUri = ValidateClientRedirectUri,
             *      OnValidateClientAuthentication = ValidateClientAuthentication,
             *      OnGrantResourceOwnerCredentials = GrantResourceOwnerCredentials,
             *  },
             *  AuthorizationCodeProvider = new AuthenticationTokenProvider
             *  {
             *      OnCreate = CreateAuthenticationCode,
             *      OnReceive = ReceiveAuthenticationCode,
             *  },
             *  RefreshTokenProvider = new AuthenticationTokenProvider
             *  {
             *      OnCreate = CreateRefreshToken,
             *      OnReceive = ReceiveRefreshToken,
             *  }
             * });
             */
            app.Map("/signout", map =>
            {
                map.Run(context =>
                {
                    context.Authentication.SignOut("External");
                    var response         = context.Response;
                    response.ContentType = "text/html";
                    response.Write("<body><html>Signed out. <a href=\"/\">Home</a></html></body>");
                    return(Task.FromResult(0));
                });
            });
            app.Map("/challenge", map =>
            {
                map.Run(context =>
                {
                    var properties                  = new AuthenticationProperties();
                    properties.RedirectUri          = "/";              // Go back to the home page after authenticating.
                    properties.Dictionary["prompt"] = "select_account"; // Google
                    context.Authentication.Challenge(properties, context.Request.Query["scheme"]);
                    return(Task.FromResult(0));
                });
            });

            /*
             * app.Map("/Account/Login", map =>
             * {
             *  map.Run(context =>
             *  {
             *      // context.Authentication.Challenge("Google");
             *      return Task.FromResult(0);
             *  });
             * });
             */
            app.Use((context, next) =>
            {
                var user = context.Authentication.User;
                if (user == null || user.Identity == null || !user.Identity.IsAuthenticated)
                {
                    var response         = context.Response;
                    response.ContentType = "text/html";
                    response.Write("<html><body>Providers:<br>\r\n");
                    foreach (var provider in context.Authentication.GetAuthenticationTypes())
                    {
                        response.Write("- <a href=\"/challenge?scheme=");
                        response.Write(provider.AuthenticationType);
                        response.Write("\">");
                        response.Write(provider.AuthenticationType);
                        response.Write("</a><br>\r\n");
                    }
                    response.Write("</body></html>\r\n");
                    return(Task.FromResult(0));
                }
                return(next());
            });

            /*
             * app.Use((context, next) =>
             * {
             *  var user = context.Authentication.User;
             *  if (user == null || user.Identity == null || !user.Identity.IsAuthenticated)
             *  {
             *      context.Authentication.Challenge();
             *      // context.Authentication.Challenge("Facebook");
             *      return Task.FromResult(0);
             *  }
             *  return next();
             * });
             */
            app.Run(async context =>
            {
                var response = context.Response;
                var user     = context.Authentication.User;
                var identity = user.Identities.First();

                response.ContentType = "text/html";
                await response.WriteAsync("<html><body>Details:<br>\r\n");
                foreach (var claim in identity.Claims)
                {
                    response.Write("- ");
                    response.Write(claim.Type);
                    response.Write(": ");
                    response.Write(claim.Value);
                    response.Write("<br>\r\n");
                }
                response.Write("<a href=\"/signout\">Signout</a>\r\n");
                response.Write("</body></html>\r\n");
            });
        }
Example #51
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            app.UseMicrosoftAccountAuthentication(
                clientId: System.Configuration.ConfigurationManager.AppSettings["MSClientID"],
                clientSecret: System.Configuration.ConfigurationManager.AppSettings["MSClientSecret"]);

            app.UseTwitterAuthentication(new TwitterAuthenticationOptions
            {
                ConsumerKey    = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"],
                ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"],
                BackchannelCertificateValidator = new CertificateSubjectKeyIdentifierValidator(new[]
                {
                    "A5EF0B11CEC04103A34A659048B21CE0572D7D47", // VeriSign Class 3 Secure Server CA - G2
                    "0D445C165344C1827E1D20AB25F40163D8BE79A5", // VeriSign Class 3 Secure Server CA - G3
                    "7FD365A7C2DDECBBF03009F34339FA02AF333133", // VeriSign Class 3 Public Primary Certification Authority - G5
                    "39A55D933676616E73A761DFA16A7E59CDE66FAD", // Symantec Class 3 Secure Server CA - G4
                    "5168FF90AF0207753CCCD9656462A212B859723B", //DigiCert SHA2 High Assurance Server C‎A
                    "B13EC36903F8BF4701D498261A0802EF63642BC3"  //DigiCert High Assurance EV Root CA
                })
            });

            app.UseFacebookAuthentication(
                appId: System.Configuration.ConfigurationManager.AppSettings["AppID"],
                appSecret: System.Configuration.ConfigurationManager.AppSettings["AppSecret"]);

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = System.Configuration.ConfigurationManager.AppSettings["ClientID"],
                ClientSecret = System.Configuration.ConfigurationManager.AppSettings["ClientSecret"]
            });
        }
Example #52
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            var option = new FacebookAuthenticationOptions
            {
                AppId     = "494454247610974",
                AppSecret = "ce8e4af1cf4be09d8b0aab15d6dc3529",
                Provider  = new FacebookAuthenticationProvider()
                {
                    OnAuthenticated = (ctx) =>
                    {
                        ctx.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", ctx.AccessToken));
                        ctx.Identity.AddClaim(new System.Security.Claims.Claim("FacebookProviderKey", ctx.Id));
                        return(Task.FromResult(0));
                    }
                },
                AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
                SendAppSecretProof = true,
                Caption            = "Facebook"
            };

            option.Scope.Add("publish_actions");
            app.UseFacebookAuthentication(option);

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "535867055862-1rus4ggpdp70qaptgdsug206fpl8ksdm.apps.googleusercontent.com",
            //    ClientSecret = "w8il1b5Y1WFNsAAfA30nz-cQ",
            //    Provider = new GoogleOAuth2AuthenticationProvider()
            //});
        }
Example #53
0
        // For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create);
            app.CreatePerOwinContext <ApplicationRoleManager>(ApplicationRoleManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            #region Microsoft

            var microsoftAuthenticationOptions = new MicrosoftAccountAuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["MsI"],
                ClientSecret = ConfigurationManager.AppSettings["MsS"],
                Provider     = new MicrosoftAccountAuthenticationProvider()
                {
                    OnAuthenticated = async context =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("MicrosoftAccessToken", context.AccessToken));
                        foreach (var claim in context.User)
                        {
                            var    claimType  = string.Format("urn:microsoft:{0}", claim.Key);
                            string claimValue = claim.Value.ToString();
                            if (!context.Identity.HasClaim(claimType, claimValue))
                            {
                                context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Microsoft"));
                            }
                        }
                    }
                }
            };
            microsoftAuthenticationOptions.Scope.Add("wl.basic");
            microsoftAuthenticationOptions.Scope.Add("wl.emails");
            microsoftAuthenticationOptions.Scope.Add("wl.birthday");
            app.UseMicrosoftAccountAuthentication(microsoftAuthenticationOptions);

            #endregion Microsoft

            #region Twitter
            var twitterAuthenticationOptions = new TwitterAuthenticationOptions()
            {
                ConsumerKey    = ConfigurationManager.AppSettings["TwtI"],
                ConsumerSecret = ConfigurationManager.AppSettings["TwtS"],
                BackchannelCertificateValidator = new CertificateSubjectKeyIdentifierValidator(
                    new[]
                {
                    "A5EF0B11CEC04103A34A659048B21CE0572D7D47", // VeriSign Class 3 Secure Server CA - G2
                    "0D445C165344C1827E1D20AB25F40163D8BE79A5", // VeriSign Class 3 Secure Server CA - G3
                    "7FD365A7C2DDECBBF03009F34339FA02AF333133", // VeriSign Class 3 Public Primary Certification Authority - G5
                    "39A55D933676616E73A761DFA16A7E59CDE66FAD", // Symantec Class 3 Secure Server CA - G4
                    "4eb6d578499b1ccf5f581ead56be3d9b6744a5e5", // VeriSign Class 3 Primary CA - G5
                    "5168FF90AF0207753CCCD9656462A212B859723B", // DigiCert SHA2 High Assurance Server C‎A
                    "B13EC36903F8BF4701D498261A0802EF63642BC3"  // DigiCert High Assurance EV Root CA
                }),
                Provider = new TwitterAuthenticationProvider()
                {
                    OnAuthenticated = async context =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("TwitterAccessToken", context.AccessToken));
                        foreach (var claim in context.UserId)
                        {
                            var    claimType  = string.Format("urn:twitter:{0}", claim);
                            string claimValue = claim.ToString();
                            if (!context.Identity.HasClaim(claimType, claimValue))
                            {
                                context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Twitter"));
                            }
                        }
                    }
                }
            };
            app.UseTwitterAuthentication(twitterAuthenticationOptions);

            #endregion Twitter

            #region Facebook

            var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
            {
                AppId     = ConfigurationManager.AppSettings["FaceI"],
                AppSecret = ConfigurationManager.AppSettings["FaceS"],
                Provider  = new FacebookAuthenticationProvider()
                {
                    OnAuthenticated = async context =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
                        foreach (var claim in context.User)
                        {
                            var    claimType  = string.Format("urn:facebook:{0}", claim.Key);
                            string claimValue = claim.Value.ToString();
                            if (!context.Identity.HasClaim(claimType, claimValue))
                            {
                                context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Facebook"));
                            }
                        }
                    }
                }
            };
            facebookAuthenticationOptions.Scope.Add("public_profile");
            facebookAuthenticationOptions.Scope.Add("email");
            facebookAuthenticationOptions.Scope.Add("user_birthday");
            app.UseFacebookAuthentication(facebookAuthenticationOptions);

            #endregion Facebook

            #region Google

            var googleAuthenticationOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["GglI"],
                ClientSecret = ConfigurationManager.AppSettings["GglS"],
                Provider     = new GoogleOAuth2AuthenticationProvider()
                {
                    OnAuthenticated = async context =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("GoogleAccessToken", context.AccessToken));
                        foreach (var claim in context.User)
                        {
                            var    claimType  = string.Format("urn:google:{0}", claim.Key);
                            string claimValue = claim.Value.ToString();
                            if (!context.Identity.HasClaim(claimType, claimValue))
                            {
                                context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Google"));
                            }
                        }
                    }
                }
            };
            googleAuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/plus.login email");
            app.UseGoogleAuthentication(googleAuthenticationOptions);

            #endregion Google

            #region LinkedIn

            var linkedinAuthenticationOptions = new LinkedInAuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["LinkI"],
                ClientSecret = ConfigurationManager.AppSettings["LinkS"],
                Provider     = new LinkedInAuthenticationProvider()
                {
                    OnAuthenticated = async context =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("LinkedInAccessToken", context.AccessToken));
                        foreach (var claim in context.User)
                        {
                            var    claimType  = string.Format("urn:linkedin:{0}", claim.Key);
                            string claimValue = claim.Value.ToString();
                            if (!context.Identity.HasClaim(claimType, claimValue))
                            {
                                context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "LinkedIn"));
                            }
                        }
                    }
                }
            };
            app.UseLinkedInAuthentication(linkedinAuthenticationOptions);

            #endregion LinkedIn

            #region GitHub

            var gitAuthanticationOptions = new GitHubAuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["GitI"],
                ClientSecret = ConfigurationManager.AppSettings["GitS"],
                Provider     = new GitHubAuthenticationProvider()
                {
                    OnAuthenticated = async context =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("GitHubAccessToken", context.AccessToken));
                        foreach (var claim in context.User)
                        {
                            var    claimType  = string.Format("urn:github:{0}", claim.Key);
                            string claimValue = claim.Value.ToString();
                            if (!context.Identity.HasClaim(claimType, claimValue))
                            {
                                context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "GitHub"));
                            }
                        }
                    }
                }
            };
            app.UseGitHubAuthentication(gitAuthanticationOptions);

            #endregion GitHub
        }
Example #54
0
        private void ConfigureIdentityProviders(IAppBuilder app, string signInAsType)
        {
            if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["GoogleClientId"]))
            {
                app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
                {
                    AuthenticationType         = "Google",
                    Caption                    = "Sign-in with Google",
                    SignInAsAuthenticationType = signInAsType,

                    ClientId     = ConfigurationManager.AppSettings["GoogleClientId"],
                    ClientSecret = ConfigurationManager.AppSettings["GoogleClientSecret"]
                });
            }
            if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["FacebookAppId"]))
            {
                var fb = new FacebookAuthenticationOptions
                {
                    AuthenticationType         = "Facebook",
                    Caption                    = "Sign-in with Facebook",
                    SignInAsAuthenticationType = signInAsType,

                    AppId     = ConfigurationManager.AppSettings["FacebookAppId"],
                    AppSecret = ConfigurationManager.AppSettings["FacebookAppSecret"],
                    Provider  = new FacebookAuthenticationProvider()
                    {
                        OnAuthenticated = (context) =>
                        {
                            context.Identity.AddClaim(
                                new System.Security.Claims.Claim(
                                    "urn:facebook:access_token",
                                    context.AccessToken, ClaimValueTypes.String, "Facebook"));

                            return(Task.FromResult(0));
                        }
                    }
                };
                fb.Scope.Add("email");
                app.UseFacebookAuthentication(fb);
            }

            //var y = new YahooAuthenticationOptions()
            //{
            //    AuthenticationType = "Yahoo",
            //    Caption = "Sign-in with Yahoo",
            //    SignInAsAuthenticationType = signInAsType,
            //    Provider = new YahooAuthenticationProvider()
            //    {
            //        OnAuthenticated = (context) =>
            //        {
            //            context.Identity.AddClaim(
            //                new Claim("AccessToken", context.AccessToken)
            //                    );
            //            return Task.FromResult(0);
            //        }
            //    },
            //    ConsumerKey = ConfigurationManager.AppSettings["YahooConsumerKey"],
            //    ConsumerSecret = ConfigurationManager.AppSettings["YahooConsumerSecret"]
            //};
            //app.UseYahooAuthentication(y);

            //var pp = new PayPalAuthenticationOptions()
            //{
            //    AuthenticationType = "PayPal",
            //    Caption = "Sign-in with PayPal",
            //    SignInAsAuthenticationType = signInAsType,
            //    Provider = new PayPalAuthenticationProvider()
            //    {

            //    },
            //    ClientId = ConfigurationManager.AppSettings["PayPalClientId"],
            //    ClientSecret = ConfigurationManager.AppSettings["PayPalClientSecret"]
            //};
            //app.UsePayPalAuthentication(pp);
        }
Example #55
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public static void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(TimeSpan.FromMinutes(30), (manager, user) => user.GenerateUserIdentityAsync(manager)),

                    // TODO: Cookies suck, use bearer tokens!
                    OnApplyRedirect = ctx =>
                    {
                        if (!IsAjaxRequest(ctx.Request) && !IsJsonRequest(ctx.Request))
                        {
                            ctx.Response.Redirect(ctx.RedirectUri);
                        }
                    }
                }
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Microsoft Auth
            var mskey = CloudConfigurationManager.GetSetting(SettingsFrontend.MicrosoftAuthenticationKey);
            var mssec = CloudConfigurationManager.GetSetting(SettingsFrontend.MicrosoftAuthenticationSecret);

            if (!string.IsNullOrWhiteSpace(mskey) && !string.IsNullOrWhiteSpace(mssec))
            {
                app.UseMicrosoftAccountAuthentication(mskey, mssec);
            }

            // Twitter Auth
            var twkey = CloudConfigurationManager.GetSetting(SettingsFrontend.TwitterAuthenticationKey);
            var twsec = CloudConfigurationManager.GetSetting(SettingsFrontend.TwitterAuthenticationSecret);

            if (!string.IsNullOrWhiteSpace(twkey) && !string.IsNullOrWhiteSpace(twsec))
            {
                app.UseTwitterAuthentication(twkey, twsec);
            }

            // Facebook Auth
            var fbkey = CloudConfigurationManager.GetSetting(SettingsFrontend.FacebookAuthenticationKey);
            var fbsec = CloudConfigurationManager.GetSetting(SettingsFrontend.FacebookAuthenticationSecret);

            if (!string.IsNullOrWhiteSpace(fbkey) && !string.IsNullOrWhiteSpace(fbsec))
            {
                // NOTE: This is the default implementation
                //app.UseFacebookAuthentication(fbkey, fbsec);

                // NOTE: This is the extended implementation
                var facebookOptions = new FacebookAuthenticationOptions
                {
                    AppId     = fbkey,
                    AppSecret = fbsec,
                    Provider  = new FacebookAuthenticationProvider
                    {
                        OnAuthenticated = context =>
                        {
                            context.Identity.AddClaim(new Claim("FacebookAccessToken", context.AccessToken));
                            return(Task.FromResult(0));
                        }
                    },
                    SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
                    SendAppSecretProof         = true
                };
                facebookOptions.Scope.Add("This is for requested permissions");
                app.UseFacebookAuthentication(facebookOptions);
            }

            // Google+ Auth
            var gokey = CloudConfigurationManager.GetSetting(SettingsFrontend.GoogleAuthenticationKey);
            var gosec = CloudConfigurationManager.GetSetting(SettingsFrontend.GoogleAuthenticationSecret);

            if (!string.IsNullOrWhiteSpace(gokey) && !string.IsNullOrWhiteSpace(gosec))
            {
                app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
                {
                    ClientId     = gokey,
                    ClientSecret = gosec
                });
            }
        }
Example #56
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            var x = new FacebookAuthenticationProvider()
            {
                OnAuthenticated = async context =>
                                  context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken))
            };

            var f = new FacebookAuthenticationOptions()
            {
                AppId     = "382105955290612",
                AppSecret = "87b50c29f0c531f22f080b72cd62a5ec",
                Provider  = x
            };

            app.UseFacebookAuthentication(f);

            //app.UseFacebookAuthentication(
            //   appId: "382105955290612",
            //   appSecret: "87b50c29f0c531f22f080b72cd62a5ec");


            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "453506101300-hrmnjibba5g7m60eda9vdgg3s96hhl8j.apps.googleusercontent.com",
                ClientSecret = "bH8ycqKLIBJIa0iio_sibDvb"
            });
        }
Example #57
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // 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 = "",
            //    ClientSecret = ""
            //});

            app.UseFacebookAuthentication(
                appId: "243379049444002",
                appSecret: "107abdaab35c277425d5fd75494be5b8");

            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "562111145256-mv6ji5o3h02rjuc59laauclle21va09a.apps.googleusercontent.com",
                ClientSecret = "7nhRwvJ0yPk-m93s5d3mJFC6"
            });
        }
Example #58
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            //app.UseFacebookAuthentication(
            //   appId: ConfigurationManager.AppSettings["Facebook_AppId"],
            //   appSecret: ConfigurationManager.AppSettings["Facebook_AppSecret"]);
            var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions
            {
                AppId     = ConfigurationManager.AppSettings["Facebook_AppId"],
                AppSecret = ConfigurationManager.AppSettings["Facebook_AppSecret"],
                Provider  = new FacebookAuthenticationProvider()
                {
                    OnAuthenticated = (context) =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
                        return(Task.FromResult(0));
                    }
                },
                SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
                SendAppSecretProof         = true
            };

            facebookOptions.Scope.Add(ConfigurationManager.AppSettings["Facebook_Scope"]);

            app.UseFacebookAuthentication(facebookOptions);

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
Example #59
0
        // 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 OAuth token based authentication
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);

            // 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"),
                ExpireTimeSpan     = TimeSpan.FromHours(4.0),
                Provider           = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });


            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);


            ModelMetadataProviders.Current = new CustomModelMetadataProvider();

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");


            // Facebook
            const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
            var          facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions
            {
                // AppId and AppSecret now stored per instance in web.config.
                AppId     = ConfigurationManager.AppSettings["fbAppId"],
                AppSecret = ConfigurationManager.AppSettings["fbAppSecret"],
                Provider  = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationProvider
                {
                    OnAuthenticated = (context) =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook"));
                        foreach (var x in context.User)
                        {
                            var    claimType  = string.Format("urn:facebook:{0}", x.Key);
                            string claimValue = x.Value.ToString();
                            if (!context.Identity.HasClaim(claimType, claimValue))
                            {
                                context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook"));
                            }
                        }
                        return(Task.FromResult(0));
                    }
                }
            };

            //Way to specify additional scopes
            facebookOptions.Scope.Add("email");



            app.UseFacebookAuthentication(facebookOptions);

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
Example #60
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public static void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context and user manager to use a single instance per request
            // TODO Is this correct to make DbContext accessible from Web application?
            app.CreatePerOwinContext(WealthEconomyContext.Create);
            app.CreatePerOwinContext <AppUserManager>(CreateUserManager);

            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Configure the application for OAuth based flow
            PublicClientId = "self";
            var OAuthServerOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath = new PathString("/api/Token"),
                Provider          = new ApplicationOAuthProvider(PublicClientId),
                //AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), // TODO ?
                AccessTokenExpireTimeSpan = TimeSpan.FromHours(3),
                AllowInsecureHttp         = AppSettings.EnvironmentType != EnvironmentType.Live
            };

            // Enable the application to use bearer tokens to authenticate users
            app.UseOAuthBearerTokens(OAuthServerOptions);

            // Configure Facebook login
            var facebookAppId     = AppSettings.FacebookAppId;
            var facebookAppSecret = AppSettings.FacebookAppSecret;

            if (!string.IsNullOrWhiteSpace(facebookAppId) && !string.IsNullOrWhiteSpace(facebookAppSecret))
            {
                var facebookAuthOptions = new FacebookAuthenticationOptions()
                {
                    AppId     = AppSettings.FacebookAppId,
                    AppSecret = AppSettings.FacebookAppSecret,
                    UserInformationEndpoint = "https://graph.facebook.com/v2.5/me?fields=email",
                    BackchannelHttpHandler  = new FacebookBackChannelHandler(),
                    CallbackPath            = new PathString("/api/Account/ExternalLoginFacebook") // Middleware is going to handle this, no need to implement
                };
                facebookAuthOptions.Scope.Add("email");
                app.UseFacebookAuthentication(facebookAuthOptions);
            }

            // Configure Google login
            var googleClientId     = AppSettings.GoogleClientId;
            var googleClientSecret = AppSettings.GoogleClientSecret;

            if (!string.IsNullOrWhiteSpace(googleClientId) && !string.IsNullOrWhiteSpace(googleClientSecret))
            {
                var googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
                {
                    ClientId     = googleClientId,
                    ClientSecret = googleClientSecret,
                    CallbackPath = new PathString("/api/Account/ExternalLoginGoogle") // Middleware is going to handle this, no need to implement
                };
                app.UseGoogleAuthentication(googleAuthOptions);
            }

            // Configure Microsoft Accounts login
            var microsoftClientId     = AppSettings.MicrosoftClientId;
            var microsoftClientSecret = AppSettings.MicrosoftClientSecret;

            if (!string.IsNullOrWhiteSpace(microsoftClientId) && !string.IsNullOrWhiteSpace(microsoftClientSecret))
            {
                var microsoftAccountAuthOptions = new MicrosoftAccountAuthenticationOptions()
                {
                    ClientId     = AppSettings.MicrosoftClientId,
                    ClientSecret = AppSettings.MicrosoftClientSecret,
                    CallbackPath = new PathString("/api/Account/ExternalLoginMicrosoft") // Middleware is going to handle this, no need to implement
                };
                microsoftAccountAuthOptions.Scope.Add("openid");
                microsoftAccountAuthOptions.Scope.Add("email");
                app.UseMicrosoftAccountAuthentication(microsoftAccountAuthOptions);
            }
        }