当前位置: 首页>>代码示例>>C#>>正文


C# IApplicationBuilder.UseGoogleAuthentication方法代码示例

本文整理汇总了C#中IApplicationBuilder.UseGoogleAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseGoogleAuthentication方法的具体用法?C# IApplicationBuilder.UseGoogleAuthentication怎么用?C# IApplicationBuilder.UseGoogleAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IApplicationBuilder的用法示例。


在下文中一共展示了IApplicationBuilder.UseGoogleAuthentication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(LogLevel.Trace);
            loggerFactory.AddDebug(LogLevel.Trace);

            app.UseDeveloperExceptionPage();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme = "Temp",
                AutomaticAuthenticate = false,
                AutomaticChallenge = false
            });

            app.UseGoogleAuthentication(new GoogleOptions
            {
                AuthenticationScheme = "Google",
                SignInScheme = "Temp",
                ClientId = "998042782978-s07498t8i8jas7npj4crve1skpromf37.apps.googleusercontent.com",
                ClientSecret = "HsnwJri_53zn7VcO1Fm7THBb"
            });

            app.UseIdentityServer();

            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
        }
开发者ID:RajMondaz,项目名称:IdentityServer4,代码行数:27,代码来源:Startup.cs

示例2: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseIISPlatformHandler();
            app.UseDeveloperExceptionPage();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                LoginPath = "/account/login",

                AuthenticationScheme = "Cookies",
                AutomaticAuthenticate = true,
                AutomaticChallenge = true
            });

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme = "Temp",
                AutomaticAuthenticate = false
            });

            app.UseGoogleAuthentication(new GoogleOptions
            {
                ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com",
                ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo",

                AuthenticationScheme = "Google",
                SignInScheme = "Temp"
            });

            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
        }
开发者ID:freemsly,项目名称:AspNet5TemplateExternalWithCallback,代码行数:32,代码来源:Startup.cs

示例3: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;

            app.UseCookieAuthentication(options =>
            {
                options.LoginPath = "/account/login";

                options.AuthenticationScheme = "Cookies";
                options.AutomaticAuthentication = true;
            }, "main");

            app.UseCookieAuthentication(options =>
            {
                options.AuthenticationScheme = "Temp";
                options.AutomaticAuthentication = false;
            }, "external");

            app.UseGoogleAuthentication(options =>
            {
                options.ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
                options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";

                options.AuthenticationScheme = "Google";
                options.SignInScheme = "Temp";
            });

            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
        }
开发者ID:okusnadi,项目名称:AspNet5TemplateExternalWithCallback,代码行数:30,代码来源:Startup.cs

示例4: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseIISPlatformHandler();

            app.UseCookieAuthentication(options =>
            {
                options.AuthenticationScheme = "Cookies";
                options.AutomaticAuthenticate = true;
                options.AutomaticChallenge = true;

                options.LoginPath = new PathString("/account/login");
            });

            app.UseCookieAuthentication(options =>
            {
                options.AuthenticationScheme = "External";
            });

            app.UseGoogleAuthentication(options =>
            {
                options.AuthenticationScheme = "Google";
                options.SignInScheme = "External";

                options.ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
                options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
            });

            app.UseClaimsTransformation(user =>
            {
                if (user.Identity.IsAuthenticated)
                {
                    user.Identities.First().AddClaim(
                        new Claim("now", DateTime.Now.ToString()));
                }

                return Task.FromResult(user);
            });

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:freemsly,项目名称:AspNet5SecuritySamples,代码行数:60,代码来源:Startup.cs

示例5: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(LogLevel.Verbose);
            loggerFactory.AddDebug(LogLevel.Verbose);

            app.UseDeveloperExceptionPage();
            app.UseIISPlatformHandler();

            app.UseIdentityServer();

            app.UseCookieAuthentication(options =>
            {
                options.AuthenticationScheme = "External";
            });

            app.UseGoogleAuthentication(options =>
            {
                options.AuthenticationScheme = "Google";
                options.SignInScheme = "External";

                options.ClientId = Configuration["GoogleIdentityProvider:ClientId"];
                options.ClientSecret = Configuration["GoogleIdentityProvider:ClientSecret"];
                options.CallbackPath = new PathString("/googlecallback");                
            });

            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
        }
开发者ID:pikoscielniak,项目名称:notifier,代码行数:28,代码来源:Startup.cs

示例6: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env)
        {
            // without static files not event html or images will be served up
            app.UseStaticFiles();
            // Need to hook this up before the other middleware is hooked up
            // this does not use the extension method
            // app.UseMiddleware<HeaderMiddleware>(new HeaderOptions {HeaderName="X-Powered-By", HeaderValue="ASPNET_CORE" });
            //using the extension method
            //app.UseCustomHeader(new HeaderOptions { HeaderName = "X-Powered-By", HeaderValue = "ASPNET_CORE" });
            // Via diagnostics.. shows the new yellow screen of death

            // Need to add .adddebug and  console logging level should watch if you want debug messages to popup
            if (env.IsDevelopment())
            {
                loggerFactory.AddConsole(LogLevel.Debug);
                loggerFactory.AddDebug();

                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            //Note order is important use identity has to come before you call
            // external login  provider else it won't work
            app.UseIdentity();
            app.UseGoogleAuthentication(new GoogleOptions()
            {
                ClientId = Configuration["OAuth:Google:clientId"],
                ClientSecret = Configuration["OAuth:Google:clientSecret"],
                CallbackPath = "/signin-google"

            });
            //Add the facebook authentication
            app.UseFacebookAuthentication(new FacebookOptions()
            {
                AppId = Configuration["OAuth:Facebook:appId"],
                AppSecret = Configuration["OAuth:Facebook:appSecret"]

            });
            //Add the Microsoft Authentication
            app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions()
            {
                ClientId = Configuration["OAuth:Microsoft:clientId"],
                ClientSecret = Configuration["OAuth:Microsoft:clientSecret"]
                //CallbackPath="/signin-microsoft"
            });

               app.UsePipelineTimer();
            app.UseMvc(routes =>
             routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}/{type?}"
                 ));
        }
开发者ID:jmurkoth,项目名称:TODOMVC,代码行数:53,代码来源:Startup.cs

示例7: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            app.UseDeveloperExceptionPage();
            app.UseStaticFiles();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme = "Cookies",
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,

                LoginPath = new PathString("/account/login")
            });

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme = "Temp",
            });

            app.UseGoogleAuthentication(new GoogleOptions
            {
                AuthenticationScheme = "Google",
                SignInScheme = "Temp",

                ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com",
                ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo"
            });

            app.UseClaimsTransformation(context =>
            {
                if (context.Principal.Identity.IsAuthenticated)
                {
                    context.Principal.Identities.First().AddClaim(new Claim("now", DateTime.Now.ToString()));
                }

                return Task.FromResult(context.Principal);
            });

            app.UseMvcWithDefaultRoute();
        }
开发者ID:ReinhardHsu,项目名称:AspNetCoreSecuritySamples,代码行数:43,代码来源:Startup.cs

示例8: Configure

        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="loggerFactory"></param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddNLog();

            try
            {
                using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
                    .CreateScope())
                {
                    serviceScope.ServiceProvider.GetService<BddContext>()
                         .Database.Migrate();
                    serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
                         .Database.Migrate();
                    serviceScope.ServiceProvider.GetService<BddContext>().EnsureSeedData();
                }
            }
            catch { }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }

            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseIdentity();

            app.UseOAuthValidation();

            app.UseOpenIddict();

            app.UseGoogleAuthentication(new GoogleOptions()
            {
                ClientId = Configuration["GOOGLE_CLIENT_ID"],
                ClientSecret = Configuration["GOOGLE_CLIENT_SECRET"]
            });

            app.UseFacebookAuthentication(new FacebookOptions()
            {
                AppId = Configuration["FACEBOOK_APP_ID"],
                AppSecret = Configuration["FACEBOOK_SECRET_ID"]
            });

            app.UseMiddleware<WebAPILoggerMiddleware>();

            app.UseMvc(routes =>
            {
                routes.MapRoute("journee",
                    template: "Journee/Index/{equipe}/{idJournee}", defaults: new { controller = "Journee", action="Index", equipe="equipe1", idJournee = 1});
                routes.MapRoute("actu",
                    template: "Journee/Detail/{url}", defaults: new { controller = "Journee", action = "Index", equipe = "equipe1", idJournee = 1 });
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Actu}/{action=Index}/{id?}");
            });

            app.UseSwagger();
            app.UseSwaggerUi();

            app.AddNLogWeb();

            using (var context = new ApplicationDbContext(app.ApplicationServices.GetRequiredService<DbContextOptions<ApplicationDbContext>>()))
            {
                context.Database.EnsureCreated();

                var applications = context.Set<OpenIddictApplication>();
                // Add Mvc.Client to the known applications.
                if (!applications.Any())
                {
                    // Note: when using the introspection middleware, your resource server
                    // MUST be registered as an OAuth2 client and have valid credentials.
                    //
                    // context.Applications.Add(new OpenIddictApplication {
                    //     Id = "resource_server",
                    //     DisplayName = "Main resource server",
                    //     Secret = Crypto.HashPassword("secret_secret_secret"),
                    //     Type = OpenIddictConstants.ClientTypes.Confidential
                    // });

                    applications.Add(new OpenIddictApplication
                    {
                        ClientId = "xamarin-auth",
                        ClientSecret = Crypto.HashPassword(Configuration["OPENIDDICT_CLIENT_SECRET"]),
                        DisplayName = "HOFC",
                        LogoutRedirectUri = "https://local.webhofc.fr/",
                        RedirectUri = "urn:ietf:wg:oauth:2.0:oob",
//.........这里部分代码省略.........
开发者ID:orome656,项目名称:HOFCServerNet,代码行数:101,代码来源:Startup.cs

示例9: Configure


//.........这里部分代码省略.........
            //app.UseWhen(context => context.Request.Path.StartsWithSegments(new PathString("/api")), branch =>
            //{ branch.UseOAuthBearerAuthentication(options =>

            //string cId = Configuration["A:G:CId"], cSe = Configuration["A:G:CSe"];
            //string cId = Configuration["AppSettings:A_G_CId"], cSe = Configuration["AppSettings:A_G_CSe"];
            string cId = Configuration["A_G_CId"], cSe = Configuration["A_G_CSe"];
            if (!String.IsNullOrEmpty(cId) && !String.IsNullOrEmpty(cSe))
            {
                mStartupLogger.LogInformation("A_G_CId and A_G_CSe from Config has been found. Initializing GoogelAuthentication.");
                app.UseCookieAuthentication(options =>
                {
                    //options.LoginPath = "/account/login";
                    options.AuthenticationScheme = "Cookies";
                    options.AutomaticAuthenticate = true;
                    //options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
                    options.ExpireTimeSpan = TimeSpan.FromDays(10);
                    options.SlidingExpiration = false;
                });

                //// from official sample; name suggest it is token based, albeit it is not named Bearer; feeling: app.UseCookieAuthentication() is exactly this
                //app.UseOAuthAuthentication("Google-AccessToken", options =>
                //{
                //    options.AuthenticationScheme = "Google-AccessToken";
                //    //options.DisplayName = "Google-AccessToken",
                //    options.ClientId = Utils.g_YmVsYUJlbG92aXRz[0];
                //    options.ClientSecret = Utils.g_YmVsYUJlbG92aXRz[1];
                //    options.CallbackPath = new PathString("/signin-google-token");
                //    options.AuthorizationEndpoint = GoogleAuthenticationDefaults.AuthorizationEndpoint;
                //    options.TokenEndpoint = GoogleAuthenticationDefaults.TokenEndpoint;
                //    options.Scope.Add("https://www.googleapis.com/auth/plus.profile.emails.read");
                //});

                // this is from the official GitHub sample https://github.com/aspnet/Identity/blob/b9be30c6cdf055394eb5ca9cd95d02419fcdf4b4/samples/IdentitySample.Mvc/Startup.cs
                app.UseGoogleAuthentication(options =>
                {
                    options.ClientId = Encoding.UTF8.GetString(Convert.FromBase64String(cId));
                    options.ClientSecret = Encoding.UTF8.GetString(Convert.FromBase64String(cSe));

                    //options.SignInScheme = null; // by default, which doesn't work itself. It needs UseCookieAuthentication()
                    //options.SignInScheme = "Google-AccessToken"; // 2015-10-02: "System.NotSupportedException"; I guess later they will support it
                    options.SignInScheme = "Cookies";
                    options.AutomaticAuthenticate = true;  // this is false by default; if it is true, all [Authorize] Actions try to log-in to Google

                    // don't touch CallbackPath then: The CallbackPath is the google middleware callback, not the application callback. You set the application callback path on the RedirectUri property on the AuthenticationProperties that you pass when you call Challenge on the IAuthenticationManager
                    //options.CallbackPath = new PathString("/TestAuth/oauthcallback");   //new PathString("/signin-google"); is the default

                    // Scopes: Official Google page is here: https://developers.google.com/+/web/api/rest/oauth
                    // Robert uses this: { "scope", "https://www.googleapis.com/auth/plus.profile.emails.read" },  // as per stackoverflow.com/a/23764783 . Despite the docs (e.g. developers.google.com/+/api/oauth#login-scopes) suggest "email", that resulted in "this app would like to have offline access" after a couple of days
                    // http://stackoverflow.com/questions/24410179/is-there-a-way-to-only-get-a-users-email-address-with-googles-oauth2-impleme
                    // Conclusion: the First item: "Know who you are on Google" is always there. Cannot make it disappear. It is Google's policy.
                    options.Scope.Add("https://www.googleapis.com/auth/plus.profile.emails.read"); // George: Robert thinks it is better then "email", but it asked ""this app would like to have offline access"" too

                    //options.AuthenticationScheme = "Google"; // this is by default
                    //options.AuthorizationEndpoint = "https://accounts.google.com/o/oauth2/auth"; // suggest token based, not cookie based
                });
            }
            else
            {
                mStartupLogger.LogWarning("A_G_CId and A_G_CSe from Config has NOT been found. Cannot initialize GoogelAuthentication.");
            }

            // Configure the HTTP request pipeline.
            app.UseStaticFiles();   // without it, the Server will not return static HTML files
            //app.UseDefaultFiles();
            //app.UseDefaultFiles(new Microsoft.AspNet.StaticFiles.DefaultFilesOptions() { DefaultFileNames = new[] { "Index.html" } });
开发者ID:gyantal,项目名称:SQHealthMonitor,代码行数:66,代码来源:Startup.cs

示例10: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(LogLevel.None);

            app.UseDatabaseErrorPage();
            app.UseDeveloperExceptionPage();
            app.UseRequestLocalization(new RequestLocalizationOptions()
            {
                SupportedCultures = new List<CultureInfo>
                {
                    new CultureInfo("en-US")
                },
                SupportedUICultures = new List<CultureInfo>
                {
                    new CultureInfo("en-US")
                },
            }, new RequestCulture(new CultureInfo("nl-NL")));

            app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());

            app.UseStaticFiles();

            app.UseIdentity();
            app.EnsureSampleData().Wait();

            var onRemoteError = new OAuthEvents()
            {
                OnRemoteError = ctx =>
                {
                    ctx.Response.Redirect("/Account/ExternalLoginCallback?RemoteError=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message));
                    ctx.HandleResponse();
                    return Task.FromResult(0);
                }
            };

            // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715
            if (_startup.Configuration["Authentication:Google:ClientId"] != null)
            {
                app.UseFacebookAuthentication(options =>
                {
                    options.AppId = _startup.Configuration["Authentication:Facebook:AppId"];
                    options.AppSecret = _startup.Configuration["Authentication:Facebook:AppSecret"];
                    options.DisplayName = "facebook";
                    options.Events = onRemoteError;

                });
                app.UseGoogleAuthentication(options =>
                {
                    options.ClientId = _startup.Configuration["Authentication:Google:ClientId"];
                    options.ClientSecret = _startup.Configuration["Authentication:Google:ClientSecret"];
                    options.DisplayName = "google plus";
                    options.Events = onRemoteError;
                });
            }
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:Pietervdw,项目名称:DBC,代码行数:61,代码来源:Startup.cs

示例11: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Shared/Error");
            }
            app.UseCors(builder =>
                builder.WithOrigins("http://https://ibalekaapi.azurewebsites.net/")
                    .AllowAnyHeader()
                );
            app.UseStaticFiles();
            app.UseSession();
            //app.UseIISPlatformHandler();
            app.UseIdentity();
            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715

            app.UseFacebookAuthentication(new FacebookOptions()
            {
                AppId = Configuration["Authentication:Facebook:AppId"],
                AppSecret = Configuration["Authentication:Facebook:AppSecret"]
            });

            app.UseGoogleAuthentication(new GoogleOptions()
            {
                ClientId = Configuration["Authentication:Google:AppId"],
                ClientSecret = Configuration["Authentication:Google:AppSecret"]
            });
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:Xabisohila,项目名称:iBalekaWeb,代码行数:44,代码来源:Startup.cs

示例12: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Enable Application Sign In Cookie
            app.UseCookieAuthentication(
                                           new CookieAuthenticationOptions
                                           {
                                               AuthenticationScheme = "Application",
                                               AutomaticAuthenticate = false,
                                               LoginPath = new PathString(Paths.LoginPath),
                                               LogoutPath = new PathString(Paths.LogoutPath)
                                           }
                                       );

            app.UseCookieAuthentication(
                                           new CookieAuthenticationOptions
                                           {
                                               AuthenticationScheme = "External",
                                               AutomaticAuthenticate = false,
                                               CookieName = CookieAuthenticationDefaults.CookiePrefix + "External",
                                               ExpireTimeSpan = TimeSpan.FromMinutes(5)
                                           }
                                       );

            // Enable google authentication
            app.UseGoogleAuthentication(
                                           new GoogleOptions
                                           {
                                               ClientId = "309638599461-a673etlplktupuk18bo12bfljgfo4tad.apps.googleusercontent.com",
                                               ClientSecret = "YQYDFkClqu6wiSCKukaQqdfW",
                                               SignInScheme = "External",
                                               AutomaticAuthenticate = false
                                           }
                                       );

            // Setup Authorization Server
            app.UseOAuthAuthorizationServer(
                                               options =>
                                               {
                                                   options.AuthorizeEndpointPath = new PathString(Paths.AuthorizePath);
                                                   options.TokenEndpointPath = new PathString(Paths.TokenPath);
                                                   options.ApplicationCanDisplayErrors = true;

            #if DEBUG
                                                   options.AllowInsecureHttp = true;
            #endif

                                                   options.Provider = new OAuthAuthorizationServerProvider
                                                   {
                                                       OnValidateClientRedirectUri = ValidateClientRedirectUri,
                                                       OnValidateClientAuthentication = ValidateClientAuthentication,
                                                       OnGrantResourceOwnerCredentials = GrantResourceOwnerCredentials,
                                                       OnGrantClientCredentials = GrantClientCredetails
                                                   };

                                                   options.AuthorizationCodeProvider = new AuthenticationTokenProvider
                                                   {
                                                       OnCreate = CreateAuthenticationCode,
                                                       OnReceive = ReceiveAuthenticationCode,
                                                   };

                                                   options.RefreshTokenProvider = new AuthenticationTokenProvider
                                                   {
                                                       OnCreate = CreateRefreshToken,
                                                       OnReceive = ReceiveRefreshToken,
                                                   };

                                                   options.AutomaticAuthenticate = false;
                                               }
                                           );

            app.UseMvc(
                          routes =>
                          {
                              routes.MapRoute(
                                                 "DefaultMvc",
                                                 "{controller}/{action}/{id?}"
                                             );

                          }
                      );
        }
开发者ID:XacronDevelopment,项目名称:oauth-aspnet,代码行数:88,代码来源:Startup.cs

示例13: Configure

        public void Configure(IApplicationBuilder app)
        {
            // Enable Application Sign In Cookie
            app.UseCookieAuthentication(
                                           options => {
                                                          options.AuthenticationScheme = "Application";
                                                          options.AutomaticAuthentication = false;
                                                          options.LoginPath = new PathString(Paths.LoginPath);
                                                          options.LogoutPath = new PathString(Paths.LogoutPath);
                                                      }
                                       );

            app.UseCookieAuthentication(
                                           options => {
                                                          options.AuthenticationScheme = "External";
                                                          options.AutomaticAuthentication = false;
                                                          options.CookieName = CookieAuthenticationDefaults.CookiePrefix + options.AuthenticationScheme;
                                                          options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
                                                      }
                                       );

            // Enable google authentication
            app.UseGoogleAuthentication(
                                           options => {
                                                          options.ClientId = "309638599461-a673etlplktupuk18bo12bfljgfo4tad.apps.googleusercontent.com";
                                                          options.ClientSecret = "YQYDFkClqu6wiSCKukaQqdfW";
                                                          options.SignInScheme = "External";
                                                          options.AutomaticAuthentication = false;
                                                      }
                                       );

            // Setup Authorization Server
            app.UseOAuthAuthorizationServer(
                                               options => {
                                                              options.AuthorizeEndpointPath = new PathString(Paths.AuthorizePath);
                                                              options.TokenEndpointPath = new PathString(Paths.TokenPath);
                                                              options.ApplicationCanDisplayErrors = true;

                                                             #if DEBUG
                                                              options.AllowInsecureHttp = true;
                                                             #endif

                                                              options.Provider = new OAuthAuthorizationServerProvider
                                                                                 {
                                                                                     OnValidateClientRedirectUri = ValidateClientRedirectUri,
                                                                                     OnValidateClientAuthentication = ValidateClientAuthentication,
                                                                                     OnGrantResourceOwnerCredentials = GrantResourceOwnerCredentials,
                                                                                     OnGrantClientCredentials = GrantClientCredetails
                                                                                 };

                                                              options.AuthorizationCodeProvider = new AuthenticationTokenProvider
                                                                                                  {
                                                                                                      OnCreate = CreateAuthenticationCode,
                                                                                                      OnReceive = ReceiveAuthenticationCode,
                                                                                                  };

                                                              options.RefreshTokenProvider = new AuthenticationTokenProvider
                                                                                             {
                                                                                                 OnCreate = CreateRefreshToken,
                                                                                                 OnReceive = ReceiveRefreshToken,
                                                                                             };

                                                              options.AutomaticAuthentication = false;
                                                          }
                                           );

            app.UseMvc(
                          routes =>
                          {
                              routes.MapRoute(
                                                 "DefaultMvc",
                                                 "{controller}/{action}/{id?}",
                                                 new { action = "Index" }
                                             );

                          }
                      );
        }
开发者ID:okusnadi,项目名称:oauth-aspnet,代码行数:78,代码来源:Startup.cs

示例14: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");

                // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
                try
                {
                    using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
                        .CreateScope())
                    {
                        serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
                             .Database.Migrate();
                    }
                }
                catch { }
            }

            

            app.UseStaticFiles();

            app.UseIdentity();

            // Add Facebook authentication. OKL.
            app.UseFacebookAuthentication(options =>
            {
                // Add app here: https://developers.facebook.com/apps/, add platform  website and add site URL. 
                // Install SecretManager tool by running this command in app folder: dnu commands install Microsoft.Extensions.SecretManager
                // Run commands to store AppId and AppSecret:
                // * user-secret set Authentication:Facebook:AppId 123123   
                // * user-secret set Authentication:Facebook:AppSecret 456456
                // Remember to add dependencies to project json: Microsoft.AspNet.Owin, Microsoft.AspNet.Authentication.Facebook
                // 
                // Tutorial on social login here: http://go.microsoft.com/fwlink/?LinkID=532715 
                //
                // After deploying to Azure, go to portal.azure.com 
                //
                // 

                options.AppId = Configuration["Authentication:Facebook:AppId"];
                options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
                options.Scope.Add("email");
                options.UserInformationEndpoint = "https://graph.facebook.com/v2.4/me?fields=id,name,email,first_name,last_name,location";
            });

            // Add Google authentication. OKL.
            app.UseGoogleAuthentication(options =>
            {
                // Remember to add dependencies in project.json: Microsoft.AspNet.Authentication.Google
                // Add application, Enable Google+ API, get clientid and clientsecret: https://console.developers.google.com
                // Set user secrets:
                // * user-secret set Authentication:Google:ClientId 123123.apps.googleusercontent.com
                // * user-secret set Authentication:Google:ClientSecret 4gwb4b242546
                options.ClientId = Configuration["Authentication:Google:ClientId"];
                options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
                options.Events = new OAuthEvents()
                {
                    OnRemoteError = ctx =>

                    {
                        ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message));
                        ctx.HandleResponse();
                        return Task.FromResult(0);
                    }
                };

            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:losol,项目名称:ShoppingList,代码行数:88,代码来源:Startup.cs

示例15: Configure

        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();

            // Configure the HTTP request pipeline.

            // Add Application Insights to the request pipeline to track HTTP request telemetry data.
            app.UseApplicationInsightsRequestTelemetry();

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseErrorPage(ErrorPageOptions.ShowAll);
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseErrorHandler("/Home/Error");
            }

            // Track data about exceptions from the application. Should be configured after all error handling middleware in the request pipeline.
            app.UseApplicationInsightsExceptionTelemetry();

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            app.UseFacebookAuthentication();
            app.UseGoogleAuthentication();
            // app.UseMicrosoftAccountAuthentication();
            // app.UseTwitterAuthentication();

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                // Uncomment the following line to add a route for porting Web API 2 controllers.
                // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
            });
        }
开发者ID:zeynepselim,项目名称:symoapp,代码行数:52,代码来源:Startup.cs


注:本文中的IApplicationBuilder.UseGoogleAuthentication方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。