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


C# IAppBuilder.UseOAuthBearerAuthentication方法代码示例

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


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

示例1: ConfigureOAuth

        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();

              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 Facebook External Login
              //FacebookAuthOptions = new FacebookAuthenticationOptions()
              //{
              //  AppId = "841670309262660",
              //  AppSecret = "8b4eba3df30d4aa95427fa9c90372462",
              //  Provider = new FacebookAuthProvider(),
              //  Scope = { "user_about_me", "user_friends", "email", "read_friendlists", "publish_stream", "user_birthday", "user_location" }
              //};

              //app.UseFacebookAuthentication(FacebookAuthOptions);
        }
开发者ID:IlyaKazlou,项目名称:PickMeUpGlobal,代码行数:30,代码来源:Startup.cs

示例2: ConfigureAuth

        public void ConfigureAuth(IAppBuilder app)
        {            
            app.CreatePerOwinContext<IdentityUserManager>(IdentityUserManager.Create);

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            PublicClientId = "self";
            OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath = new PathString("/OAuth/Token"),
                Provider = new ApplicationOAuthProvider(PublicClientId),
                AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(5),                
                AllowInsecureHttp = true
            };

            app.UseOAuthBearerTokens(OAuthOptions);            
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "852925537385-9t4d8fg869kpi1dlm58v77277b70lc6e.apps.googleusercontent.com",
            //    ClientSecret = "078iMDZvE2JKYZc8-a5TeEey",
            //    Provider = new GoogleAuthProvider()
            //});
        }
开发者ID:TkachukOrest,项目名称:Catch-Me-If-You-Can,代码行数:26,代码来源:Startup.AuthConfig.cs

示例3: Configuration

 public void Configuration(IAppBuilder app)
 {
     app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
     {
         AccessTokenFormat = new JwtFormat(AppConstants.Audience, new X509CertificateSecurityTokenProvider("AS", GetSigningCertificate()))
     });
 }
开发者ID:RolandTG,项目名称:OwinSamples,代码行数:7,代码来源:Startup.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            var logger = new Logger();
            var container = CreateUnityContainer(logger);
            logger.Info("Starting Israel Hiking Server.");
            var config = new HttpConfiguration();
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
            {
                AccessTokenProvider = new OsmAccessTokenProvider(
                    container.Resolve<IHttpGatewayFactory>(),
                    container.Resolve<LruCache<string, TokenAndSecret>>(),
                    logger)
            });
            WebApiConfig.Register(config);

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new CoordinateConverter());
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new GeometryConverter());
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new FeatureCollectionConverter());
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new FeatureConverter());
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new AttributesTableConverter());
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new ICRSObjectConverter());
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new GeometryArrayConverter());
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new EnvelopeConverter());

            config.Services.Add(typeof(IExceptionLogger), logger);
            config.DependencyResolver = new UnityResolver(container);
            InitializeServices(container);
            app.UseWebApi(config);
            logger.Info("Israel Hiking Server is up and running.");
        }
开发者ID:IsraelHikingMap,项目名称:Site,代码行数:33,代码来源:Startup.cs

示例5: ConfigureOAuth

        private void ConfigureOAuth(IAppBuilder app)
        {
            //var serverOptions = new OAuthAuthorizationServerOptions()
            //{
            //    AuthenticationMode=Microsoft.Owin.Security.AuthenticationMode.Active,
            //    AllowInsecureHttp = true,
            //    TokenEndpointPath = new PathString("/token"),
            //    AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
            //    Provider = new CIRAuthorizationServerProvider()
            //};
            //app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            var implicitGrantServerOptions = new OAuthAuthorizationServerOptions
            {
                AuthorizeEndpointPath= new PathString("/token"),
                Provider= new CIRImplicitAuthorizationServerProvider(),
                AllowInsecureHttp = true,
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(100)
            };

            app.UseOAuthAuthorizationServer(implicitGrantServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
            {
                AuthenticationType="Bearer",
                AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active
            });
        }
开发者ID:codenewa,项目名称:CookieToToken,代码行数:27,代码来源:Startup.cs

示例6: ConfigureAuth

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

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Configure the application for OAuth based flow
            PublicClientId = "self";
            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
            };
            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthOptions);
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
            app.UseOAuthBearerAuthentication(OAuthBearerOptions);

            facebookAuthOptions = new FacebookAuthenticationOptions
            {
                AppId = "1543886725935090",
                AppSecret = "63ab7a49e991177caf72e3ec8f2247cc",
                Provider = new FacebookAuthProvider()
            };
            app.UseFacebookAuthentication(facebookAuthOptions);
        }
开发者ID:DarkNormal,项目名称:PosseNetAPIApp,代码行数:36,代码来源:Startup.Auth.cs

示例7: ConfigureOAuth

        public void ConfigureOAuth(IAppBuilder app)
        {
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
                Provider = new OAuthAuthorizationServerProvider
                {
                    OnValidateClientAuthentication = async c=>c.Validated(),
                    OnGrantResourceOwnerCredentials = async c =>
                    {
                        using (var repo = new AuthRepository())
                        {
                            var user = await repo.FindUser(c.UserName, c.Password);
                            if (user == null)
                            {
                                c.Rejected();
                                throw new ApiException("User not existed or wrong password.");
                            }
                        }
                        var identity = new ClaimsIdentity(c.Options.AuthenticationType);
                        identity.AddClaims(new[] {new Claim(ClaimTypes.Name, c.UserName), new Claim(ClaimTypes.Role, "user")});
                        if (string.Equals(c.UserName, AppConfig.Manager, StringComparison.InvariantCultureIgnoreCase))
                            identity.AddClaims(new[] {new Claim(ClaimTypes.Name, c.UserName), new Claim(ClaimTypes.Role, "manager")});
                        c.Validated(identity);
                    }
                },
            });
        }
开发者ID:Malkiat-Singh,项目名称:webApiAngular,代码行数:32,代码来源:Startup.cs

示例8: ConfigureAuth

        public void ConfigureAuth(IAppBuilder app)
        {
            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AuthenticationType = Constant.GrantTypes.AuthenticationType,
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString(WebConfig.TokenPath),
                AccessTokenExpireTimeSpan = TimeSpan.FromSeconds(int.Parse(WebConfig.AccessTokenExpireTimeSpan)),
                Provider = new OAuth2AuthorizationServerProvider(),
                RefreshTokenProvider = new OAuth2RefreshTokenProvider()
            };
            //AuthenticationType :认证类型
            //AllowInsecureHttp : 如果允许客户端的 return_uri 参数不是 HTTPS 地址, 则设置为 true
            //TokenEndpointPath : 客户端应用可以直接访问并得到访问令牌的地址, 必须以前倒斜杠 "/" 开始, 例如: /Token
            //AccessTokenExpireTimeSpan :Token过期时间
            //Provider : 应用程序提供和 OAuth 认证中间件交互的 IOAuthAuthorizationServerProvider 实例, 通常可以使用默认的
            //OAuthAuthorizationServerProvider , 并设置委托函数即可
            //RefreshTokenProvider :刷新令牌, 如果这个属性没有设置, 则不能从 /Token 刷新令牌

            // 令牌生成
            app.UseOAuthAuthorizationServer(OAuthServerOptions);

            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            //跨域处理
            app.UseCors(CorsOptions.AllowAll);
        }
开发者ID:doscanner,项目名称:GF,代码行数:27,代码来源:Startup.Auth.cs

示例9: ConfigureOAuth

        public void ConfigureOAuth(IAppBuilder app, HttpConfiguration config)
        {
            UserManagerFactory = () =>
            {
                try
                {
                    var userRepository = config.DependencyResolver.GetService(typeof(IUserRepository));
                    var userManager =
                        new ApplicationUserManager(userRepository as IUserRepository);
                    return userManager;
                }
                catch (Exception)
                {
                    return null;
                }
            };

            app.CreatePerOwinContext(UserManagerFactory);

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

            app.UseOAuthAuthorizationServer(oAuthServerOptions);

            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
        }
开发者ID:jonahtaxt,项目名称:Effisoft.RookieBetting,代码行数:31,代码来源:Startup.Auth.cs

示例10: ConfigureOAuth

        public void ConfigureOAuth(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Login"),
                Provider = new CookieAuthenticationProvider()
                {
                    OnApplyRedirect = ctx =>
                    {
                        if (!IsApiRequest(ctx.Request))
                        {
                            ctx.Response.Redirect(ctx.RedirectUri);
                        }
                    }
                }
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            //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);
            var OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

            // Token Generation
            app.UseOAuthAuthorizationServer(NinjectResolver.CreateKernel.Value.Get<MyOAuthAuthorizationServerOptions>().GetOptions());
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions { Provider = new ApplicationOAuthBearerAuthenticationProvider()});
        }
开发者ID:sirAspex,项目名称:InoDrive,代码行数:28,代码来源:AuthConfig.cs

示例11: ConfigureAuth

 // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
 public void ConfigureAuth(IAppBuilder app)
 {
     app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
     {
         Provider = new ClientOAuthBearerAuthenticationProvider()
     });
 }
开发者ID:quangnc0503h,项目名称:ecommerce,代码行数:8,代码来源:Startup.Auth.cs

示例12: ConfigureOAuth

        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);
        }
开发者ID:juliepromact,项目名称:WebApi,代码行数:34,代码来源:Startup.cs

示例13: ConfigureOAuth

        /// <summary>
        /// Se realiza la configuración de autorización
        /// </summary>
        /// <param name="app"></param>
        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());
            app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

            googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId = "185157178718-8qc15td8nefjssrai2md8eiodr151m8u.apps.googleusercontent.com",
                ClientSecret = "tmnYb6S99BJPWVbv45Ha8Mf-",
                Provider = new GoogleAuthProvider()
            };
            app.UseGoogleAuthentication(googleAuthOptions);

        }
开发者ID:correobasura,项目名称:repositorioAngujarNet,代码行数:30,代码来源:Startup.cs

示例14: ConfigureOAuthTokenGeneration

        public static void ConfigureOAuthTokenGeneration(IAppBuilder app)
        {
            // configure database context and user manager to use a single instance per request
            app.CreatePerOwinContext(ngk.DataLayer.EFDbContext.AuthorizationContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);

            app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);

            var token = new CustomJwtFormat("ngKBaseAngular");

            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                // production should not allow insecure http
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(20),
                Provider = new Providers.CustomOAuthProvider(),
                RefreshTokenProvider = new Providers.RefreshTokenProvider(),
                AccessTokenFormat = token
            };

            // OAuth 2.0 Bearer Access Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
        }
开发者ID:innercitypressure,项目名称:ngKeyBase,代码行数:25,代码来源:Configuration.cs

示例15: ConfigureAuth

        public void ConfigureAuth(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            // TODO: figure out how to get client certificates
            // config.MessageHandlers.Add(new CertificateHandler());
            config.MessageHandlers.Add(new ValidateRequestHandler());

            OAuthBearerOptions = new OAuthAuthorizationServerOptions();
            app.UseOAuthAuthorizationServer(OAuthBearerOptions);

            OAuthBearerAuthenticationOptions = new OAuthBearerAuthenticationOptions();
            app.UseOAuthBearerAuthentication(OAuthBearerAuthenticationOptions);

            bool loadAssemblies = false;
            if (bool.TryParse(ConfigurationManager.AppSettings["LoadAssemblyForTest"], out loadAssemblies))
            {
                config.Services.Replace(typeof(IAssembliesResolver), new AssemblyResolver());
            }

            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter("Bearer"));

            app.UseWebApi(config);
        }
开发者ID:divyang4481,项目名称:STS,代码行数:32,代码来源:OwinStartUp.cs


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