Esempio n. 1
0
        private static void ConfigureFacebookLogin(IAppBuilder app, string signInAsType, IApplicationSettingRepository applicationSettingRepository)
        {
            var facebookEnabled = applicationSettingRepository.GetOrCreateByName <bool>("ExternalProvider_Facebook_Enabled");

            if (facebookEnabled)
            {
                var facebookAppId     = applicationSettingRepository.GetOrCreateByName <string>("ExternalProvider_Facebook_AppId");
                var facebookAppSecret = applicationSettingRepository.GetOrCreateByName <string>("ExternalProvider_Facebook_AppSecret");

                if (!string.IsNullOrWhiteSpace(facebookAppId) && !string.IsNullOrWhiteSpace(facebookAppSecret))
                {
                    var facebookOptions = new FacebookAuthenticationOptions
                    {
                        AppId     = facebookAppId,
                        AppSecret = facebookAppSecret,
                        Caption   = "Facebook",
                        SignInAsAuthenticationType = signInAsType,
                        AuthenticationType         = "Facebook",
                        Provider = new FacebookAuthenticationProvider
                        {
                            OnAuthenticated = async context =>
                            {
                                foreach (var claim in context.User)
                                {
                                    switch (claim.Key)
                                    {
                                    case "first_name":
                                        context.Identity.AddClaim(new System.Security.Claims.Claim(Constants.ClaimTypes.GivenName, claim.Value.ToString(), "XmlSchemaString", "Facebook"));
                                        break;

                                    case "last_name":
                                        context.Identity.AddClaim(new System.Security.Claims.Claim(Constants.ClaimTypes.FamilyName, claim.Value.ToString(), "XmlSchemaString", "Facebook"));
                                        break;
                                    }
                                }

                                await Task.FromResult(false);
                            }
                        },
                        BackchannelHttpHandler  = new FacebookBackChannelHandler(),
                        UserInformationEndpoint = "https://graph.facebook.com/v2.5/me?fields=id,name,email,first_name,last_name"
                    };
                    facebookOptions.Scope.Add("email");
                    facebookOptions.Scope.Add("public_profile");
                    app.UseFacebookAuthentication(facebookOptions);
                }
            }
        }
Esempio n. 2
0
        private static void ConfigureGoogleLogin(IAppBuilder app, string signInAsType, IApplicationSettingRepository applicationSettingRepository)
        {
            var googleEnabled = applicationSettingRepository.GetOrCreateByName <bool>("ExternalProvider_Google_Enabled");

            if (googleEnabled)
            {
                var googleClientId     = applicationSettingRepository.GetOrCreateByName <string>("ExternalProvider_Google_ClientId");
                var googleClientSecret = applicationSettingRepository.GetOrCreateByName <string>("ExternalProvider_Google_ClientSecret");

                if (!string.IsNullOrWhiteSpace(googleClientId) && !string.IsNullOrWhiteSpace(googleClientSecret))
                {
                    app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
                    {
                        Caption      = "Google",
                        ClientId     = googleClientId,
                        ClientSecret = googleClientSecret,
                        SignInAsAuthenticationType = signInAsType,
                        AuthenticationType         = "Google"
                    });
                }
            }
        }
Esempio n. 3
0
        private static void ConfigureFacebookLogin(IAppBuilder app, string signInAsType, IApplicationSettingRepository applicationSettingRepository)
        {
            var facebookEnabled = applicationSettingRepository.GetOrCreateByName<bool>("ExternalProvider_Facebook_Enabled");
            if (facebookEnabled)
            {
                var facebookAppId = applicationSettingRepository.GetOrCreateByName<string>("ExternalProvider_Facebook_AppId"); 
                var facebookAppSecret = applicationSettingRepository.GetOrCreateByName<string>("ExternalProvider_Facebook_AppSecret");

                if (!string.IsNullOrWhiteSpace(facebookAppId) && !string.IsNullOrWhiteSpace(facebookAppSecret))
                {
                    var facebookOptions = new FacebookAuthenticationOptions
                    {
                        AppId = facebookAppId,
                        AppSecret = facebookAppSecret,
                        Caption = "Facebook",
                        SignInAsAuthenticationType = signInAsType,
                        AuthenticationType = "Facebook",
                        Provider = new FacebookAuthenticationProvider
                        {
                            OnAuthenticated = async context =>
                                {
                                    foreach (var claim in context.User)
                                    {
                                        switch (claim.Key)
                                        {
                                            case "first_name":
                                                context.Identity.AddClaim(new System.Security.Claims.Claim(Constants.ClaimTypes.GivenName, claim.Value.ToString(), "XmlSchemaString", "Facebook"));
                                                break;
                                            case "last_name":
                                                context.Identity.AddClaim(new System.Security.Claims.Claim(Constants.ClaimTypes.FamilyName, claim.Value.ToString(), "XmlSchemaString", "Facebook"));
                                                break;
                                        }
                                    }

                                    await Task.FromResult(false);
                                }
                        },
                        BackchannelHttpHandler = new FacebookBackChannelHandler(),
                        UserInformationEndpoint = "https://graph.facebook.com/v2.5/me?fields=id,name,email,first_name,last_name"
                    };
                    facebookOptions.Scope.Add("email");
                    facebookOptions.Scope.Add("public_profile");
                    app.UseFacebookAuthentication(facebookOptions);
                }
            }
        }
Esempio n. 4
0
        private static void ConfigureGoogleLogin(IAppBuilder app, string signInAsType, IApplicationSettingRepository applicationSettingRepository)
        {
            var googleEnabled = applicationSettingRepository.GetOrCreateByName<bool>("ExternalProvider_Google_Enabled");
            if (googleEnabled)
            {
                var googleClientId = applicationSettingRepository.GetOrCreateByName<string>("ExternalProvider_Google_ClientId");
                var googleClientSecret = applicationSettingRepository.GetOrCreateByName<string>("ExternalProvider_Google_ClientSecret"); 

                if (!string.IsNullOrWhiteSpace(googleClientId) && !string.IsNullOrWhiteSpace(googleClientSecret))
                {
                    app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
                    {
                        Caption = "Google",
                        ClientId = googleClientId,
                        ClientSecret = googleClientSecret,
                        SignInAsAuthenticationType = signInAsType,
                        AuthenticationType = "Google"
                    });
                }
            }
        }