Exemplo n.º 1
0
        private void ConfigureAuth(IAppBuilder app)
        {
            var cookieOptions = new CookieAuthenticationOptions
            {
                LoginPath          = new PathString("/Account/Login"),
                AuthenticationType = "ExternalCookie",
                ExpireTimeSpan     = TimeSpan.FromMinutes(60),
            };

            app.UseCookieAuthentication(cookieOptions);

            app.SetDefaultSignInAsAuthenticationType(cookieOptions.AuthenticationType);

            var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
            {
                ClientId     = "633929508797-o00j4ncrrtuc4e1ghlmq56ns0h1ls2va.apps.googleusercontent.com",
                ClientSecret = "ASR0zjlk4xedIzVxtRkVuoys",
                Provider     = new GoogleOAuth2AuthenticationProvider()
                {
                }
            };

            googleOAuth2AuthenticationOptions.Scope.Add("email");

            app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
        }
Exemplo n.º 2
0
        public static void ConfigureAdditionalIdentityProviders(IAppBuilder app, string signInAsType)
        {
            var google = new GoogleOAuth2AuthenticationOptions
            {
                AuthenticationType         = "Google",
                SignInAsAuthenticationType = signInAsType,
                ClientId     = "767400843187-8boio83mb57ruogr9af9ut09fkg56b27.apps.googleusercontent.com",
                ClientSecret = "5fWcBT0udKY7_b6E3gEiJlze"
            };

            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);
        }
Exemplo n.º 3
0
        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.FromMinutes(30),
                Provider             = new SimpleAuthorizationServerProvider(),
                RefreshTokenProvider = new SimpleRefreshTokenProvider()
            };

            app.UseOAuthAuthorizationServer(oAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());


            //Configure Google External Login
            googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "xxx",
                ClientSecret = "xxx",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(googleAuthOptions);

            //Configure Facebook External Login
            facebookAuthOptions = new FacebookAuthenticationOptions()
            {
                AppId     = "xxx",
                AppSecret = "xxx",
                Provider  = new FacebookAuthProvider()
            };
            app.UseFacebookAuthentication(facebookAuthOptions);
        }
Exemplo n.º 4
0
        private static GoogleOAuth2AuthenticationOptions CreateGoogleAuthenticationOptions()
        {
            var googleAuthenticationOptions = new GoogleOAuth2AuthenticationOptions
            {
                ClientId     = ConfigurationManager.AppSettings["googleClientId"],
                ClientSecret = ConfigurationManager.AppSettings["googleClientSecret"],
                Provider     = new GoogleOAuth2AuthenticationProvider()
                {
                    OnAuthenticated = context =>
                    {
                        context.Identity.AddClaim(new Claim(ClaimTypes.Gender, context.User.GetValue("gender").ToString()));
                        return(Task.FromResult(0));
                    }
                }
            };

            // default scopes
            googleAuthenticationOptions.Scope.Add("openid");
            googleAuthenticationOptions.Scope.Add("profile");
            googleAuthenticationOptions.Scope.Add("email");

            // additional scope(s)
            googleAuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/plus.me");

            return(googleAuthenticationOptions);
        }
Exemplo n.º 5
0
        private void ConfigureOAuth(IAppBuilder app)
        {
            //use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            var options = new OAuthAuthorizationServerOptions
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                Provider = new SimpleAuthrizationServerProvider(new AuthRepository())
            };

            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

            app.UseOAuthAuthorizationServer(options);
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);

            //Configure Google External Login
            GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions
            {
                ClientId     = "671830126309-drlernfdnh6n09oavvqlkv9rpk98p45k.apps.googleusercontent.com",
                ClientSecret = "FAA0hz8ssyL4x4Hawsf-HbRH",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(GoogleAuthOptions);
        }
Exemplo n.º 6
0
        private static GoogleOAuth2AuthenticationOptions GetGoogleAuthenticationOptions()
        {
            var options = new GoogleOAuth2AuthenticationOptions
            {
                ClientId     = GetClientID("Google"),
                ClientSecret = GetClientSecret("Google"),
                Provider     = new GoogleOAuth2AuthenticationProvider
                {
                    OnApplyRedirect = context =>
                    {
                        var dictionary = new Dictionary <string, string>
                        {
                            {
                                "openid.realm",
                                new Uri(WebConfigurationManager.AppSettings["AuthenticationProvider.Google.OpenId2.Realm"]).GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)
                            },
                        };
                        context.Response.Redirect(WebUtilities.AddQueryString(context.RedirectUri, dictionary));
                    },
                },
                BackchannelHttpHandler = OpenIdMigrationWebrequestHandler
            };

            options.Scope.Add("openid");
            options.Scope.Add("profile");
            options.Scope.Add("email");
            options.Scope.Add("https://www.googleapis.com/auth/userinfo.profile");
            return(options);
        }
        public async Task ReplyPathWillRejectIfAccessTokenIsMissing()
        {
            var options = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId               = "Test Id",
                ClientSecret           = "Test Secret",
                BackchannelHttpHandler = new TestHttpMessageHandler
                {
                    Sender = async req =>
                    {
                        return(await ReturnJsonResponse(new object()));
                    }
                }
            };
            var server           = CreateServer(options);
            var properties       = new AuthenticationProperties();
            var correlationKey   = ".AspNet.Correlation.Google";
            var correlationValue = "TestCorrelationId";

            properties.Dictionary.Add(correlationKey, correlationValue);
            properties.RedirectUri = "/me";
            var state       = options.StateDataFormat.Protect(properties);
            var transaction = await SendAsync(server,
                                              "https://example.com/signin-google?code=TestCode&state=" + Uri.EscapeDataString(state),
                                              correlationKey + "=" + correlationValue);

            transaction.Response.StatusCode.ShouldBe(HttpStatusCode.Redirect);
            transaction.Response.Headers.Location.ToString().ShouldContain("error=access_denied");
        }
Exemplo n.º 8
0
        private void ConfigureOAuthExternal(IAppBuilder app)
        {
            //user a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
            _OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

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

            //Google will be our 3rd party
            _googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "403744615341-hej6i7qeakd0trpnc02r57rub34qa75k.apps.googleusercontent.com",
                ClientSecret = "rV9TV4DjrRahLPOlijTQSmQX",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(_googleAuthOptions);
        }
Exemplo n.º 9
0
        public void Configuration(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            var options = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "147873998968-fb2tu4na0p34re8nkv14vpnd80t1mgm1.apps.googleusercontent.com",
                ClientSecret = "EA_o1m1e8E7LZ3UBCNRq1EPT",
                CallbackPath = new PathString("/Account/ExternalLoginCallback")
            };

            options.Scope.Add("email");
            app.UseGoogleAuthentication(options);

            app.UseFacebookAuthentication(
                appId: "2239949612912907",
                appSecret: "e05661d1cc2910580bc4b796b5d26cd7"
                );
        }
Exemplo n.º 10
0
        public void ConfigureOAuth(IAppBuilder app)
        {
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

            GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "xxx",
                ClientSecret = "axax",
                Provider     = new GoogleAuthProvider()
            };

            app.UseGoogleAuthentication(GoogleAuthOptions);

            FacebookAuthOptions = new FacebookAuthenticationOptions()
            {
                AppId     = "1487705754840266",
                AppSecret = "58f0103d9d2bafb53cac09742a16cbed",
                Provider  = new FacebookAuthProvider()
            };

            app.UseFacebookAuthentication(FacebookAuthOptions);

            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString(TokenPath),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(TokenExpirationDays),
                Provider = new SimpleAuthorizationServerProvider()
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
        }
Exemplo n.º 11
0
        public ExternalIdentityProviderService WithGoogleAuthentication(string clientId, string clientSecret)
        {
            if (string.IsNullOrWhiteSpace(clientId))
            {
                throw new ArgumentNullException(nameof(clientId));
            }

            if (string.IsNullOrEmpty(clientSecret))
            {
                throw new ArgumentNullException(nameof(clientId));
            }

            configurators.Add((appBuilder, signInAsType) =>
            {
                var google = new GoogleOAuth2AuthenticationOptions
                {
                    AuthenticationType         = "Google",
                    SignInAsAuthenticationType = signInAsType,
                    ClientId     = clientId,
                    ClientSecret = clientSecret
                };
                appBuilder.UseGoogleAuthentication(google);
            });

            return(this);
        }
Exemplo n.º 12
0
        public void ConfigureOAuth(IAppBuilder app)
        {
            // Configure the db context and user manager to use a single instance per request
            app.CreatePerOwinContext(MeetMeDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);

            // Enable the application to 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 = "MeetMeApp";
            OAuthOptions   = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath         = new PathString("/Token"),
                Provider                  = new ApplicationOAuthProvider(PublicClientId),
                AuthorizeEndpointPath     = new PathString("/api/Account/ExternalLogin"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                // In production mode set AllowInsecureHttp = false
                AllowInsecureHttp = true
            };

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

            GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "554910020383-d4foh3220vd51cmmlenk1577a49ac2uj.apps.googleusercontent.com",
                ClientSecret = "9kOla5a1A3C5UZXnjz5CcPew",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(GoogleAuthOptions);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        //http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/
        private static void ConfigureOAuth(IAppBuilder app)
        {
            var oAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new SimpleAuthorizationServerProvider()
            };

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "1037398895413-bl8isjjb8it51g10rhrkdaa7q6a8bo1c.apps.googleusercontent.com",
                ClientSecret = "uuQI0aECvZJGrYQKD6y0qfXT",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(googleAuthOptions);

            app.UseOAuthAuthorizationServer(oAuthServerOptions);
            var authenticationOptions = new OAuthBearerAuthenticationOptions()
            {
                AuthenticationMode = AuthenticationMode.Active
            };

            app.UseOAuthBearerAuthentication(authenticationOptions);
        }
Exemplo n.º 15
0
        public IEnumerable <OwinMiddlewareRegistration> GetOwinMiddlewares()
        {
            var workContext = _workContextAccessor.GetContext();
            var settings    = workContext.CurrentSite.As <GoogleSettingsPart>();

            if (settings == null || !settings.IsValid())
            {
                return(Enumerable.Empty <OwinMiddlewareRegistration>());
            }

            var authenticationOptions = new GoogleOAuth2AuthenticationOptions {
                ClientId     = settings.ClientId,
                ClientSecret = settings.ClientSecret,
                CallbackPath = new PathString(GetCallbackPath(workContext, settings))
            };

            return(new List <OwinMiddlewareRegistration> {
                new OwinMiddlewareRegistration {
                    Priority = Constants.General.OpenIdOwinMiddlewarePriority,
                    Configure = app => {
                        app.UseGoogleAuthentication(authenticationOptions);
                    }
                }
            });
        }
Exemplo n.º 16
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"),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                Provider             = new SimpleAuthorizationServerProvider(),
                RefreshTokenProvider = new SimpleRefreshTokenProvider()
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);
            //Configure Google External Login
            googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "936007638974-2ko9tqdmv3ifomlblhlrnninkdoe9bkt.apps.googleusercontent.com",
                ClientSecret = "4_GR4_4JPnglWQOnSnwOZzlV",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(googleAuthOptions);
        }
Exemplo n.º 17
0
        public void ConfigureOAuth(IAppBuilder app)
        {
            //use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

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

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

            googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "969151181075-bd7rambibsa042jsis2seuqp68a5d3j7.apps.googleusercontent.com",
                ClientSecret = "YQartfe8AWXyE-i1gCKd08mP",
                Provider     = new GoogleAuthProvider()
            };

            app.UseGoogleAuthentication(googleAuthOptions);

            facebookAuthOptions = new FacebookAuthenticationOptions()
            {
                AppId     = "582178408640492",
                AppSecret = "e874f4d192b0aaf4b520c85a822688f5",
                Provider  = new FacebookAuthProvider()
            };
            app.UseFacebookAuthentication(facebookAuthOptions);
        }
Exemplo n.º 18
0
        private static void RegisterExternalAuth(IAppBuilder app)
        {
//app.UseFacebookAuthentication(
            //   appId: "",
            //   appSecret: "");

            if (!string.IsNullOrWhiteSpace(ApiSecretsStorage.GoogleClientId) &&
                !string.IsNullOrWhiteSpace(ApiSecretsStorage.GoogleClientSecret))
            {
                var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions()
                {
                    ClientId     = ApiSecretsStorage.GoogleClientId,
                    ClientSecret = ApiSecretsStorage.GoogleClientSecret,
                };
                googleOAuth2AuthenticationOptions.Scope.Add("email");
                app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
            }

            if (!string.IsNullOrWhiteSpace(ApiSecretsStorage.VkClientId) &&
                !string.IsNullOrWhiteSpace(ApiSecretsStorage.VkClientSecret))
            {
                app.UseVKontakteAuthentication(new VKontakteAuthenticationOptions()
                {
                    Scope = new List <string>()
                    {
                        "email"
                    },
                    ClientId     = ApiSecretsStorage.VkClientId,
                    ClientSecret = ApiSecretsStorage.VkClientSecret,
                });
            }
        }
        public void ConfigureAuth(IAppBuilder app)
        {
            var cookieOptions = new CookieAuthenticationOptions
            {
                CookieName         = "fq54010K",
                AuthenticationType = "ExternalCookie",
                LoginPath          = new PathString("/Account/Login/")
            };

            app.UseCookieAuthentication(cookieOptions);
            app.SetDefaultSignInAsAuthenticationType(cookieOptions.AuthenticationType);

            var googleOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "34141593357-62hkeoos2ajdh7sl40p8nn5eqf1ua7bf.apps.googleusercontent.com",
                ClientSecret = "Rwl7HXa7rUZTOGKzz9xk4J7X",
                CallbackPath = new PathString("/Account/ExternalLoginCallback/"),
                Provider     = new GoogleOAuth2AuthenticationProvider()
                {
                    OnAuthenticated = context =>
                    {
                        context.Identity.AddClaim(new Claim("urn:token:google", context.AccessToken));
                        return(Task.FromResult(true));
                    }
                }
            };

            app.UseGoogleAuthentication(googleOptions);
        }
 public LocustThirdPartyOptions()
 {
     MicrosoftAccount = new MicrosoftAccountAuthenticationOptions();
     Twitter          = new TwitterAuthenticationOptions();
     Facebook         = new FacebookAuthenticationOptions();
     Google           = new GoogleOAuth2AuthenticationOptions();
 }
Exemplo n.º 21
0
        public void ConfigureAuth(IAppBuilder app)
        {
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

            var oAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                Provider             = new SimpleAuthorizationServerProvider(),
                RefreshTokenProvider = new SimpleRefreshTokenProvider()
            };

            app.UseOAuthAuthorizationServer(oAuthServerOptions);
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);

            GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "zzz",
                ClientSecret = "zzz",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(GoogleAuthOptions);

            FacebookAuthOptions = new FacebookAuthenticationOptions()
            {
                AppId     = "zzz",
                AppSecret = "zzz",
                Provider  = new FacebookAuthProvider()
            };
            app.UseFacebookAuthentication(FacebookAuthOptions);
        }
Exemplo n.º 22
0
        public void ConfigureOAuth(IAppBuilder app)
        {
            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                Provider             = new SimpleAuthorizationServerProvider(),
                RefreshTokenProvider = new SimpleRefreshTokenProvider()
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            //Configure Google External Login
            googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "90666907944-o02ijc0nes4e6u26b7jmk7b6sr8dclr9.apps.googleusercontent.com",
                ClientSecret = "VwuUWkX4wCTn2UssEX4vfCP6",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(googleAuthOptions);

            //Configure Facebook External Login
            facebookAuthOptions = new FacebookAuthenticationOptions()
            {
                AppId     = "146338829036652",
                AppSecret = "4c24328bfaa6d1801a98e72d91c3c600",
                Provider  = new FacebookAuthProvider()
            };
            app.UseFacebookAuthentication(facebookAuthOptions);
        }
Exemplo n.º 23
0
        public void ConfigureAuth(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ExternalCookie
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            var authOptions = new GoogleOAuth2AuthenticationOptions
            {
                ClientId     = "1030197237184-1qtod5qe8of2f4unucqqq9pf2r04cj6u.apps.googleusercontent.com",
                ClientSecret = "qh9zPd4YGvzvW0EVBqh184Sd"
            };

            authOptions.Scope.Add("profile");
            authOptions.Scope.Add("email");
            authOptions.Provider = new GoogleOAuth2AuthenticationProvider
            {
                OnAuthenticated = context =>
                {
                    var profileUrl = context.User["image"]["url"].ToString();
                    context.Identity.AddClaim(new Claim(ClaimTypes.Uri, profileUrl));
                    return(Task.FromResult(0));
                }
            };
            app.UseGoogleAuthentication(authOptions);
        }
Exemplo n.º 24
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"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new SimpleAuthorizationServerProvider(),
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            //Configure Google External Login
            googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "667051559939-pu1h6ibq07kbadrqi8ahg53vj2lmprvl.apps.googleusercontent.com",
                ClientSecret = "7YOwaSyGtLJURcDSUkSeu5mh",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(googleAuthOptions);

            //Configure Facebook External Login
            facebookAuthOptions = new FacebookAuthenticationOptions()
            {
                AppId     = "1651381111770506",
                AppSecret = "3be1a8a9a949507b9f674da022212b19",
                Provider  = new FacebookAuthProvider()
            };
            app.UseFacebookAuthentication(facebookAuthOptions);
        }
Exemplo n.º 25
0
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the user manager and signin manager to use a single instance per request
            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("/Application/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(1),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            var options = new GoogleOAuth2AuthenticationOptions
            {
                ClientId     = "xyz.apps.googleusercontent.com",
                ClientSecret = "xyz"
            };

            options.Scope.Add("email");

            app.UseGoogleAuthentication(options);
        }
Exemplo n.º 26
0
        public void ConfigureOAuth(IAppBuilder app)
        {
            //use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

            //Configure Google External Login
            googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "1062017231759-a1o19lh9oi0m3iubbs6f6e4lc06i3lio.apps.googleusercontent.com",
                ClientSecret = "e8pJjQFzWl8I_ojnZTtuUFA5",
                Provider     = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(googleAuthOptions);

            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                Provider             = new SimpleAuthorizationServerProvider(),
                RefreshTokenProvider = new SimpleRefreshTokenProvider()
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);
        }
Exemplo n.º 27
0
        public void GoogleOAuth2Configuration(IAppBuilder app)
        {
            app.UseAuthSignInCookie();

            var option = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = "581497791735.apps.googleusercontent.com",
                ClientSecret = "-N8rQkJ_MKbhpaxyjdVYbFpO",
            };

            app.UseGoogleAuthentication(option);

            app.Run(async context =>
            {
                if (context.Authentication.User == null || !context.Authentication.User.Identity.IsAuthenticated)
                {
                    var authenticationProperties = new AuthenticationProperties();
                    authenticationProperties.Dictionary.Add("access_type", "custom_accessType");
                    authenticationProperties.Dictionary.Add("approval_prompt", "custom_approval_prompt");
                    authenticationProperties.Dictionary.Add("login_hint", "custom_login_hint");

                    context.Authentication.Challenge(authenticationProperties, "Google");
                    await context.Response.WriteAsync("Unauthorized");
                }
            });
        }
Exemplo n.º 28
0
        private void SetupIdentity(IAppBuilder app)
        {
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            var GOOGLE_ID     = ConfigurationManager.AppSettings[GenericNames.GOOGLE_CLIENT_ID];
            var GOOGLE_SECRET = ConfigurationManager.AppSettings[GenericNames.GOOGLE_CLIENT_SECRET];

            if (GOOGLE_ID != null && GOOGLE_SECRET != null)
            {
                GoogleOAuth2AuthenticationOptions googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
                {
                    ClientId     = ConfigurationManager.AppSettings[GenericNames.GOOGLE_CLIENT_ID],
                    ClientSecret = ConfigurationManager.AppSettings[GenericNames.GOOGLE_CLIENT_SECRET],
                    Provider     = new GoogleCustomAuthenticationProvider()
                };
                app.UseGoogleAuthentication(googleAuthOptions);
            }
            else
            {
                TokenInfoList.Remove(GoogleTokenInfo.NAME_PROVIDER);
            }
            // Token Generation
            app.UseOAuthAuthorizationServer(OptionsServerOAuth);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
        }
Exemplo n.º 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
            // 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: "DE9rrDoJOJhbrGR9BBMpyBwa6",
            //    consumerSecret: "bsO1Wz3qx3kUsSIVk0s1ycIWsekDvR8P33m45CDjoU9Qi6YgY1");

            IFacebookAuthenticationFactory facebookAuthenticationFactory = new FacebookAuthenticationFactory();
            FacebookAuthenticationOptions  facebookAuthenticationOptions = facebookAuthenticationFactory.CreateAuthenticationOptions();

            app.UseFacebookAuthentication(facebookAuthenticationOptions);

            GoogleOAuth2AuthenticationOptions googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["oAuth2.Google.ClientId"],
                ClientSecret = ConfigurationManager.AppSettings["oAuth2.Google.ClientSecret"]
            };

            googleOAuth2AuthenticationOptions.Scope.Add("profile");
            googleOAuth2AuthenticationOptions.Scope.Add("email");

            app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
        }
Exemplo n.º 30
0
        public static void ConfigureAuth(IAppBuilder app)
        {
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
                LoginPath          = new PathString("/auth/login"),
                CookieName         = "Auth",
                ExpireTimeSpan     = TimeSpan.FromDays(1),
                Provider           = new CookieAuthenticationProvider
                {
                    OnApplyRedirect = context =>
                    {
                        if (!IsApiRequest(context))
                        {
                            context.Response.Redirect(context.RedirectUri);
                        }
                    },
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromDays(1));
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            var authenticationOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = ClientId,
                ClientSecret = "m_3UUpAcinahC7R7m-4nzNZq",
                CallbackPath = new PathString("/auth/signin-google")
            };

            authenticationOptions.AuthorizationEndpoint += "?prompt=select_account";

            authenticationOptions.Provider = new GoogleOAuth2AuthenticationProvider()
            {
                OnAuthenticated = context =>
                {
                    using (var db = new CrimsonClubsDbContext())
                    {
                        var user = db.Users.FirstOrDefault(u => u.Email == context.Email);

                        if (user == null)
                        {
                            user = context.NewUser();

                            db.Users.Add(user);
                            db.SaveChanges();
                        }

                        context.Identity.AddClaims(user);
                    }

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

            app.UseGoogleAuthentication(authenticationOptions);
        }