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


C# IAppBuilder.UseIdentityServerBearerTokenAuthentication方法代码示例

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


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

示例1: Configuration

        public void Configuration(IAppBuilder app)
        {
            JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                // The HttpSignatureValidation middleware looks for another middleware called PoP
                AuthenticationType = "PoP",

                Authority = "https://localhost:44333/core",
                RequiredScopes = new[] { "write" },

                // client credentials for the introspection endpoint
                ClientId = "write",
                ClientSecret = "secret",

                // this is used to extract the access token from the pop token
                TokenProvider = new OAuthBearerAuthenticationProvider
                {
                    OnRequestToken = async ctx =>
                    {
                        ctx.Token = await DefaultPopTokenProvider.GetAccessTokenFromPopTokenAsync(ctx.OwinContext.Environment);
                    }
                }
            });

            // this registers the middleware that does the signature validation of the request against the pop token secret
            app.UseHttpSignatureValidation();

            app.UseWebApi(WebApiConfig.Register());
        }
开发者ID:camainc,项目名称:IdentityServer3.Samples,代码行数:31,代码来源:Startup.cs

示例2: Configuration

        public void Configuration(IAppBuilder app)
        {
            // # 1) Bearer token authentication
            // Nuget source code and documentation https://github.com/IdentityServer/IdentityServer3.AccessTokenValidation
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                // accept only tokens issued by IdentityServer
                Authority = IdentityServerUrl,
                // accept only tokens that are issued for our API
                RequiredScopes = new[] { "tickets_api" }, // There is an scope defined in Identity Server that some clients can use 

                ValidationMode = ValidationMode.Local // JWT Local validation
            });

            // # 2) Web api 
            var config = new HttpConfiguration();

            // routing
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "api/{controller}/{action}");

            // JSON formatter
            config.Formatters.Clear();
            config.Formatters.Add(new JsonMediaTypeFormatter());

            app.UseWebApi(config);
        }
开发者ID:softwarejc,项目名称:angular2-aspmvc-core1-getting-started,代码行数:27,代码来源:Startup.cs

示例3: Configuration

        public void Configuration(IAppBuilder app)
        {
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
            JwtSecurityTokenHandler.OutboundClaimTypeMap = new Dictionary<string, string>();

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "http://localhost:49907/core",
                ValidationMode = ValidationMode.Local, // JWT
                TokenProvider = new OAuthBearerAuthenticationProvider()
                {
                    OnValidateIdentity = ctx =>
                    {
                        var claims = new List<Claim>(ctx.Ticket.Identity.Claims);
                        claims.Add(new Claim("name", "johnny"));
                        var identity = new ClaimsIdentity(claims, ctx.Ticket.Identity.AuthenticationType, "name", "role");
                        return Task.FromResult(ctx.Validated(identity));
                    }
                }
            });

            var config = new HttpConfiguration();
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.MapHttpAttributeRoutes();
            app.UseWebApi(config);
        }
开发者ID:CrescentFresh,项目名称:AccessTokenValidationIISLogging,代码行数:26,代码来源:Startup.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", inner =>
            {
                var option = new IdentityServerOptions
                {
                    RequireSsl = false,
                    SiteName = "Same Server Identity Service",
                    EnableWelcomePage = false,
                    Factory = new IdentityServerServiceFactory()
                            .UseInMemoryClients(Clients.Get())
                            .UseInMemoryScopes(Scopes.Get())
                            .UseInMemoryUsers(Users.Get())
                };

                inner.UseIdentityServer(option);
            });

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions()
            {
                Authority = "http://localhost:4560/identity",
                ValidationMode = ValidationMode.Both,
                RequiredScopes = new[] { "read", "api1" },
                DelayLoadMetadata = true
            });


            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug() // change with your desired log level
                .WriteTo.Trace()
                //.WriteTo.File(@"C:\myPath.txt") // remember to assign proper writing privileges on the file
                .CreateLogger();

        }
开发者ID:oneandy,项目名称:IdentityServer3-Single-Poject-Sample,代码行数:34,代码来源:Startup.cs

示例5: Configuration

        public void Configuration(IAppBuilder app)
        {
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

            // Unterstützung für identity server access tokens
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
                {
                    // basis URL
                    Authority = "https://localhost:44345",
                    ValidationMode = ValidationMode.Local,

                    // konfigurierte scope in identity server
                    RequiredScopes = new[] { "webapi" }
                });

            // web api konfiguration mit attribute routing
            var webApiConfig = new HttpConfiguration();
            webApiConfig.MapHttpAttributeRoutes();

            // CORS aktivieren
            var corsAttribute = new EnableCorsAttribute("https://localhost:44300", "*", "*");
            webApiConfig.EnableCors(corsAttribute);

            // kein anonymer zugriff erlaubt
            webApiConfig.Filters.Add(new AuthorizeAttribute());

            // web api einbinden
            app.UseWebApi(webApiConfig);
        }
开发者ID:EdWin1409,项目名称:DotNetProIdentityServerArtikel,代码行数:29,代码来源:Startup.cs

示例6: Configuration

        public void Configuration(IAppBuilder app)
        {
            // Disables default mapping of incoming claims
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

            // Configures authentication using "Bearer" tokens with IdentityServer.
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                // The issuer of the tokens
                Authority = "https://timesheetsts.azurewebsites.net",
                ValidationMode = ValidationMode.Local,
                RequiredScopes = new[] { TimesheetConstants.ApiScope }, // When accessing our API, a token must have the "timesheet-api" scope
                NameClaimType = "name", // Rename the default Name/Role claimtypes from their SOAP versions to IdentityServer.
                RoleClaimType = "role"
            });

            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes(); // Use attribute routing

            config.SuppressDefaultHostAuthentication(); // If IIS has set a User on our request, remove it again
            config.Filters.Add(new AuthorizeAttribute()); // Users must be logged on for each request
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // And look for a Bearer token to authenticate a user

            config.Formatters.Remove(config.Formatters.XmlFormatter); // Remove the XML formatter, we're only supporting JSON
            config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver() // Set up camelCase names
            };

            // Validation for our POST models
            FluentValidationModelValidatorProvider.Configure(config);

            // Start the Web API middleware
            app.UseWebApi(config);
        }
开发者ID:wcabus,项目名称:MADN-oAuth,代码行数:35,代码来源:Startup.cs

示例7: Configuration

        public void Configuration(IAppBuilder app)
        {
            JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "https://localhost:44333/core",
                RequiredScopes = new[] { "api" },
                NameClaimType = "name",
                RoleClaimType = "role",

                // client credentials for the introspection endpoint
                ClientId = "angularMaterial",
                ClientSecret = Guid.NewGuid().ToString()
            });

            var configuration = new HttpConfiguration();
            configuration.MapHttpAttributeRoutes();

            var jsonFormatter = configuration.Formatters.OfType<JsonMediaTypeFormatter>().FirstOrDefault();

            if (jsonFormatter != null)
            {
                jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }

            app.UseResourceAuthorization(new AuthorizationManager());

            app.UseWebApi(configuration);

            app.UseNancy();
            app.UseStageMarker(PipelineStage.MapHandler);
        }
开发者ID:ianlovell,项目名称:openidconnect,代码行数:33,代码来源:Startup.cs

示例8: Configuration

        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();
            WebApiConfig.Register(config);
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "http://localhost:52401",//Your url here
                RequiredScopes = new[] {"api"}
            });

            app.UseWebApi(config);
            var factory = InMemoryFactory.Create(Config.GetUsers().ToList(), Config.GetClients(), Config.GetScopes());
            app.UseIdentityServer(new IdentityServerOptions
            {
                IssuerUri = "urn:identity",
                Factory = factory,
                RequireSsl = false, //DO NOT DO THIS IN PRODUCTION
                LoggingOptions = new LoggingOptions
                {
                 EnableWebApiDiagnostics   = true,
                 WebApiDiagnosticsIsVerbose = true
                },
                SigningCertificate = LoadCertificate()

            });
            app.UseNLog();
        }
开发者ID:yuva2achieve,项目名称:SingleSignOnDemo,代码行数:27,代码来源:Startup.cs

示例9: Configuration

        public void Configuration(IAppBuilder app)
        {
           
            // token validation
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = Constants.IdentityServerUri,
                RequiredScopes = new[] { "apiAccess" }
            });

            // add app local claims per request
            app.UseClaimsTransformation(incoming =>
            {
                // either add claims to incoming, or create new principal
                var appPrincipal = new ClaimsPrincipal(incoming);
                incoming.Identities.First().AddClaim(new Claim("appSpecific", "some_value"));

                return Task.FromResult(appPrincipal);
            });

            app.UseCors(CorsOptions.AllowAll);

            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            // web api configuration
            app.UseWebApi(config);
        }
开发者ID:mcginkel,项目名称:identityServer3Example,代码行数:27,代码来源:Startup.cs

示例10: Configuration

        public void Configuration(IAppBuilder app)
        {
            // Create container
            var container = SetupContainer();

            // Setup token based authentication
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "https://localhost:44302",
                ValidationMode = ValidationMode.ValidationEndpoint,

                RequiredScopes = new[] { "Api" }
            });

            // Configure CORS (Cross Origin Resource Sharing)
            app.UseCors(CorsOptions.AllowAll);

            // Create new http configuration
            var config = new HttpConfiguration();

            // Configure webapi
            WebApiConfig.Configure(config, container.GetInstance<IDependencyResolver>());

            // Register web api
            app.UseWebApi(config);
        }
开发者ID:robinvanderknaap,项目名称:SkaeleAuthorizationServer,代码行数:26,代码来源:Startup.cs

示例11: GetHttpConfiguration

        public override HttpConfiguration GetHttpConfiguration(IAppBuilder app)
        {
            var builder = new ContainerBuilder();
            var config = new HttpConfiguration();

            //Autofac Filters primarily to make in memory testing easier
            builder.Register(c => new IdSrvAuthorizeAttributeFake())
                .As<IAutofacAuthorizationFilter>()
                .AsWebApiAuthorizationFilterFor<ClaimsController>()
                .InstancePerRequest();

            builder.Register(c => new IdSrvAuthorizeAttributeFake())
                .As<IAutofacAuthorizationFilter>()
                .AsWebApiAuthorizationFilterFor<LinkExternalProviderController>(c => c.Post(default(LinkExternalProviderController.RegisterExternalBindingModel)))
                .InstancePerRequest();

            builder.Register(c => new IdSrvAuthorizeAttributeFake())
                .As<IAutofacAuthorizationFilter>()
                .AsWebApiAuthorizationFilterFor<UnLinkExternalProviderController>()
                .InstancePerRequest();

            builder.RegisterType<MrUserAccountServiceFake>()
                .As<IMrUserAccountService>()
                .InstancePerRequest();

            builder.RegisterType<LinkedAccountClaim>().InstancePerLifetimeScope();

            builder.Register(c => new GoogleOAuth2AuthenticationOptions()
            {
                ClientId = "405547628913-afp6rob22l602dembl7eqnseb9vmrbqs.apps.googleusercontent.com",
                ClientSecret = "ENxb5ZPcOl_BHSWfUTUQecxw",
                Provider = new GoogleAuthProvider()
            });

            builder.Register(c => new FacebookAuthenticationOptions()
            {
                AppId = "1617509121824168",
                AppSecret = "dc36301f5ec7a3e30adf3cb6a1a8fddc",
                Provider = new FacebookAuthProvider()
            });

            builder.RegisterApiControllers(typeof(Startup).Assembly);

            builder.RegisterWebApiFilterProvider(config);

            var container = builder.Build();

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "https://localhost:44333/core",
                RequiredScopes = new[] { "api1" }
            });

            app.UseCors(CorsOptions.AllowAll);
            app.UseAutofacMiddleware(container);

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            return config;
        }
开发者ID:darrenschwarz,项目名称:Karama.Identity.Net46,代码行数:60,代码来源:TestStartupConfiguration.cs

示例12: Configuration

 public void Configuration(IAppBuilder app)
 {
     // token validation
     app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
     {
         Authority = "https://localhost:44333/core"
     });
 }
开发者ID:huoxudong125,项目名称:SwaggerDemoApi,代码行数:8,代码来源:Startup.cs

示例13: Configuration

        public void Configuration(IAppBuilder app)
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            app.Use(async (context, next) =>
            {
                if (context.Request.Method != "OPTIONS" && context.Request.Cookies.Any())
                {
                    var cookie = context.Request.Cookies["Halo-Secure"];
                    if (!string.IsNullOrEmpty(cookie))
                    {
                        context.Request.Headers.Remove("Authorization");
                        context.Request.Headers.Add("Authorization", new[] { "Bearer " + cookie }); //.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", cookie.Cookies[0].Value);
                    }
                }

                await next.Invoke();
            });

            var corsPolicy = new CorsPolicy
            {
                AllowAnyMethod = true,
                AllowAnyHeader = true,
                AllowAnyOrigin = false,
                SupportsCredentials = true
            };
            corsPolicy.Origins.Add("http://localhost:32150");
            //corsPolicy.Origins.Add("https://localhost:32150");
            //corsPolicy.Origins.Add("http://localhost:32150/");
            //corsPolicy.Origins.Add("https://localhost:32150/");
            corsPolicy.ExposedHeaders.Add("X-Custom-Header");
            app.UseCors(new Microsoft.Owin.Cors.CorsOptions()
            {
                PolicyProvider = new CorsPolicyProvider
                {
                    PolicyResolver = context => Task.FromResult(corsPolicy)
                }
            });

            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
                {
                    Authority = "https://HFL0100:44333",
                    RequiredScopes = new[] { "api1" },
                    ValidationMode = ValidationMode.Local,
                    AuthenticationType = "Bearer",
                    AuthenticationMode = AuthenticationMode.Active,
            });
            // configure web api
            var config = new HttpConfiguration();
            config.Filters.Add(new AuthorizeAttribute());
            config.MapHttpAttributeRoutes();
            app.UseWebApi(config);
        }
开发者ID:okusnadi,项目名称:IdentityServer3_WebApi_AngularJs_SSO_BearerToken,代码行数:54,代码来源:Startup.cs

示例14: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "https://localhost:44300/idsvr",
                RequiredScopes = new[] { "write" }
            });

            // web api configuration
            app.UseWebApi(WebApiConfiguration());
        }
开发者ID:dtuit,项目名称:IdentityServer_BasicSetup,代码行数:11,代码来源:Startup.cs

示例15: Configuration

        public void Configuration(IAppBuilder app)
        {
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
                {
                    Authority = "https://localhost:44333/core",
                    RequiredScopes = new[] { "write" }
                });

            app.UseWebApi(WebApiConfig.Register());
        }
开发者ID:MauricioArroyo,项目名称:IdentityServer3.Samples,代码行数:12,代码来源:Startup.cs


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