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


C# IAppBuilder.UseResourceAuthorization方法代码示例

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


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

示例1: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseResourceAuthorization(new AuthorizationManager());

            var clientId = (string)ConfigurationManager.AppSettings["oauth2.clientid"];
            var authority = (string)ConfigurationManager.AppSettings["oauth2.authority"];

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions {
                Authority = authority,
                RequiredScopes = new[] { clientId },
            });

            app.UseResourceAuthorization(new AuthorizationManager());
        }
开发者ID:mindfulsoftware,项目名称:oauth2Demo,代码行数:14,代码来源:Startup.cs

示例2: 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

示例3: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", idsrvApp => idsrvApp.UseIdentityServer(new IdentityServerOptions
            {
                SiteName = "Embedded IdentityServer",
                IssuerUri = "https://idsrv3/embedded",
                SigningCertificate = LoadCertificate(),

                Factory = InMemoryFactory.Create(
                    users: Users.Get(),
                    clients: Clients.Get(),
                    scopes: Scopes.Get())
            }));

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                Authority = "https://localhost:44304/identity",

                ClientId = "mvc",
                Scope = "openid profile roles",
                RedirectUri = "https://localhost:44304/",

                SignInAsAuthenticationType = "Cookies"
            });

            app.UseResourceAuthorization(new AuthorizationManager());
        }
开发者ID:shcheahgmail,项目名称:DotNetSamples,代码行数:32,代码来源:Startup.cs

示例4: Configuration

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

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                ClientId = "implicitclient-cardeal",
                Authority = Constants.BaseAddress,
                RedirectUri = "http://localhost:57870/",
                ResponseType = "id_token token",
                Scope = "openid email write",
                SignInAsAuthenticationType = "Cookies",

                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenValidated = SecurityTokenValidated
                }
            });

            app.UseResourceAuthorization(new AuthorizationManager());

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
开发者ID:saitolabs,项目名称:POC-AspNet-SSO,代码行数:31,代码来源:Startup.cs

示例5: Configuration

        public void Configuration(IAppBuilder app)
        {
            var cookie = new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookie",
                ExpireTimeSpan = TimeSpan.FromMinutes(20),
                LoginPath = new PathString("/Login"),
            };
            app.UseCookieAuthentication(cookie);

            app.UseResourceAuthorization(new ChinookAuthorization());
        }
开发者ID:Bihari,项目名称:Thinktecture.IdentityModel,代码行数:12,代码来源:Startup.cs

示例6: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseResourceAuthorization(new AuthorizationManager());

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = ExpenseTrackerConstants.IdSrvBase,
                RequiredScopes = new[] { "expensetrackerapi" }

            });

            app.UseWebApi(WebApiConfig.Register());
        }
开发者ID:rgeyer777,项目名称:expensetracker,代码行数:13,代码来源:Startup.cs

示例7: Configuration

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

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

            app.UseResourceAuthorization(new AuthorizationManager());

            app.UseWebApi(WebApiConfig.Register());
        }
开发者ID:okusnadi,项目名称:DemoIdeSrv3AngularJS,代码行数:14,代码来源:Startup.cs

示例8: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                LoginPath = new PathString("/Home/Login"),
                SlidingExpiration = true,
                CookieHttpOnly = true,  // already defaults to true
                CookieSecure = CookieSecureOption.SameAsRequest,
                Provider = new CookieAuthenticationProvider
                {
                    OnApplyRedirect = ctx =>
                    {
                        if (!ctx.Request.IsAjaxRequest())
                        {
                            ctx.Response.Redirect(ctx.RedirectUri);
                        }
                    }
                }
            });

            app.UseResourceAuthorization(new CustomAuthorizationManager());
            ConfigureWebApi(app);
        }
开发者ID:cecilphillipTK,项目名称:webapi2-security-samples,代码行数:23,代码来源:Startup.cs

示例9: Configuration

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

            app.UseCookieAuthentication(new CookieAuthenticationOptions {
                AuthenticationType = "Cookies"
            });

            app.UseResourceAuthorization(new AuthorizationManager());

            var clientId = (string)ConfigurationManager.AppSettings["oauth2.clientid"];
            var authority = (string)ConfigurationManager.AppSettings["oauth2.authority"];
            var redirectUri = (string)ConfigurationManager.AppSettings["oauth2.redirect"];

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions {
                Authority = authority,
                ClientId = clientId,
                RedirectUri = redirectUri,
                ResponseType = "id_token token",
                Scope = "openid roles demo-website",

                SignInAsAuthenticationType = "Cookies",
            });
        }
开发者ID:mindfulsoftware,项目名称:oauth2Demo,代码行数:24,代码来源:Startup.cs

示例10: Configuration

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


            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                Authority = Constants.IdentityServerUri,
                ClientId = Constants.ImplicitClient,
                Scope = "openid profile roles apiAccess",
                RedirectUri = Constants.ImplicitClientUri,
                ResponseType = "id_token token",
                UseTokenLifetime = false,
                SignInAsAuthenticationType = "Cookies",

                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenValidated = async n =>
                    {
                        var nid = new ClaimsIdentity(
                            n.AuthenticationTicket.Identity.AuthenticationType,
                            "givenname",
                            "role");

                        // get userinfo data
                        var userInfoClient = new UserInfoClient(new Uri(n.Options.Authority + "/connect/userinfo"), n.ProtocolMessage.AccessToken);

                        var userInfo = await userInfoClient.GetAsync();

                        if (userInfo.Claims != null)
                        {
                            userInfo.Claims.ToList().ForEach(ui => nid.AddClaim(new Claim(ui.Item1, ui.Item2)));
                        }


                        // keep the id_token for logout
                        nid.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken));

                        // add access token for sample API
                        nid.AddClaim(new Claim("access_token", n.ProtocolMessage.AccessToken));

                        // keep track of access token expiration
                        nid.AddClaim(new Claim("expires_at", DateTimeOffset.Now.AddSeconds(int.Parse(n.ProtocolMessage.ExpiresIn)).ToString()));

                        n.AuthenticationTicket = new AuthenticationTicket(nid, n.AuthenticationTicket.Properties);
                    },

                    RedirectToIdentityProvider = n =>
                    {
                        if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
                        {
                            var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");

                            if (idTokenHint != null)
                            {
                                n.ProtocolMessage.PostLogoutRedirectUri = Constants.ImplicitClientUri;
                                n.ProtocolMessage.IdTokenHint = idTokenHint.Value;
                            }
                        }

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

            app.UseResourceAuthorization(new AuthorizationManager());
        }
开发者ID:mcginkel,项目名称:identityServer3Example,代码行数:73,代码来源:Startup.cs

示例11: ConfigureAuth

            public void ConfigureAuth(IAppBuilder app)
            {

            //   LG.Owin.Security.Enviornment.Startup.ConfigAuth(app);

            AntiForgeryConfig.UniqueClaimTypeIdentifier = Thinktecture.IdentityServer.Core.Constants.ClaimTypes.Subject;
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

            app.UseResourceAuthorization(
                new AuthorizationManager());

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies",
                AuthenticationMode = AuthenticationMode.Active
            });

            app.SetDefaultSignInAsAuthenticationType("External");
            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                Authority = LG.Owin.Security.Config.ServerSettings.Url,
                ClientId = LG.Owin.Security.Config.ClientSettings.ClientID,
                ClientSecret = "51FC860D-07D3-4296-9147-2E40AC7FF6C8".Sha256(),
                Scope = "openid profile roles all_claims",
                ResponseType = "id_token token",
                RedirectUri = "https://www.1888md.com/Members/",
                SignInAsAuthenticationType = "Cookies",
                UseTokenLifetime = false,
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenValidated = async n =>
                    {
                        var nid = new ClaimsIdentity(
                            n.AuthenticationTicket.Identity.AuthenticationType,
                              Thinktecture.IdentityServer.Core.Constants.ClaimTypes.GivenName,

                        Thinktecture.IdentityServer.Core.Constants.ClaimTypes.Role);

                        var userInfoClient = new UserInfoClient(
                          new Uri(n.Options.Authority + "/connect/userinfo"),
                          n.ProtocolMessage.AccessToken);

                        var userInfo = await userInfoClient.GetAsync();
                        userInfo.Claims.ToList().ForEach(ui => nid.AddClaim(new Claim(ui.Item1, ui.Item2)));

                        //userInfo.Claims.ToList().ForEach(ui => nid.AddClaim(
                        //    new Claim(ui.Item1, ui.Item2)));

                        // keep the id_token for logout
                        nid.AddClaim(new Claim("id_token",
                            n.ProtocolMessage.IdToken));

                        // add access token for sample API
                        nid.AddClaim(new Claim("access_token",
                            n.ProtocolMessage.AccessToken));

                        // keep track of access token expiration
                        nid.AddClaim(new Claim("expires_at",
                            DateTimeOffset.Now.AddSeconds(int.Parse(n.ProtocolMessage.ExpiresIn)).ToString()));

                        // add some other app specific claim
                        //nid.AddClaim(new Claim("app_specific", "some data"));
                        n.AuthenticationTicket = new AuthenticationTicket(nid, n.AuthenticationTicket.Properties);

                    },
                    RedirectToIdentityProvider = async n =>
                    {
                        if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.AuthenticationRequest)
                        {
                            await GetWaiter();
                            var sb = new StringBuilder();
                            var custom = n.OwinContext.Get<Dictionary<string, string>>("OpenIdConnect.Parameters");
                            if (custom != null)
                            {
                                foreach (var c in custom)
                                {
                                    // ReSharper disable once UseStringInterpolation
                                    sb.Append(string.Format(" {0}={1}", c.Key, c.Value));
                                }
                            }
                            if (sb.Length > 0) { sb.Remove(0, 1); }
                            n.ProtocolMessage.AcrValues = sb.ToString();
                        }
                        if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
                        {
                            var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");
                            if (idTokenHint != null) { n.ProtocolMessage.IdTokenHint = idTokenHint.Value; }
                        }
                    }
                }
            });
        }
开发者ID:vmfdesign,项目名称:Portal,代码行数:92,代码来源:Startup.Auth.cs

示例12: Configuration

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

            app.SetupFilters(config);
            app.SetupRoutes(config);
            app.SetupDependencies(config);

            app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions() {
                AccessTokenExpireTimeSpan = TimeSpan.FromHours(24),
                AllowInsecureHttp = true,
                Provider = new SimpleAuthorizationServerProvider(),
                TokenEndpointPath = new PathString("/api/token")
            });

            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions() { });

            app.UseResourceAuthorization(new AppAuthorization());

            app.UseWebApi(config);
        }
开发者ID:Olif,项目名称:WebApiBoilerPlate,代码行数:21,代码来源:Startup.cs

示例13: Configuration

        public void Configuration(IAppBuilder app)
        {
            AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject;
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

            app.Map(
                "/identity",
                idsrvApp =>
                    {
                        idsrvApp.UseIdentityServer(
                            new IdentityServerOptions
                                {
                                    SiteName = "Embedded IdentityServer",
                                    SigningCertificate = LoadCertificate(),
                                    Factory =
                                        new IdentityServerServiceFactory().UseInMemoryUsers(
                                            Users.Get())
                                        .UseInMemoryClients(Clients.Get())
                                        .UseInMemoryScopes(Scopes.Get()),

                                    // Use this for Facebook login
                                    //AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions
                                    //{
                                    //    IdentityProviders = ConfigureIdentityProviders
                                    //}
                                });
                    });

            app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = "Cookies" });

            // Point the OpenID Connect middleware (also in Startup.cs) to our embedded version of IdentityServer and use the previously configured client configuration
            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                    {
                        Authority = "https://localhost:44301/identity",
                        ClientId = "mvc",
                        Scope = "openid profile roles sampleApi",
                        RedirectUri = "https://localhost:44301/",
                        ResponseType = "id_token token",
                        SignInAsAuthenticationType = "Cookies",
                        UseTokenLifetime = false,

                        // Do the claims transformations
                        Notifications = new OpenIdConnectAuthenticationNotifications
                                            {

                            SecurityTokenValidated = async n =>
                                                    {
                                                        var nid = new ClaimsIdentity(
                                                            n.AuthenticationTicket.Identity.AuthenticationType,
                                                            Constants.ClaimTypes.GivenName,
                                                            Constants.ClaimTypes.Role);

                                                        // get userinfo data
                                                        var userInfoClient = new UserInfoClient(
                                                            new Uri(n.Options.Authority + "/connect/userinfo"),
                                                            n.ProtocolMessage.AccessToken);

                                                        var userInfo = await userInfoClient.GetAsync();
                                                        userInfo.Claims.ToList().ForEach(ui => nid.AddClaim(new Claim(ui.Item1, ui.Item2)));

                                                        // keep the id_token for Logout - the client has to prove its identity to the
                                                        // logout endpoint to make sure we redirect to the right URL (and not some spammer/phishing page).
                                                        nid.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken));

                                                        // add access token for sample API
                                                        nid.AddClaim(new Claim("access_token", n.ProtocolMessage.AccessToken));

                                                        // keep track of access token expiration
                                                        nid.AddClaim(new Claim("expires_at", DateTimeOffset.Now.AddSeconds(int.Parse(n.ProtocolMessage.ExpiresIn)).ToString()));

                                                        // add some other app specific claim
                                                        nid.AddClaim(new Claim("app_specific", "some data"));

                                                        n.AuthenticationTicket = new AuthenticationTicket(
                                                            nid,
                                                            n.AuthenticationTicket.Properties);
                                                    },

                            // attach the id_token when the user logs out and we make the roundtrip to IdentityServer.
                            RedirectToIdentityProvider = n =>
                                                    {
                                                        if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
                                                        {
                                                            var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");

                                                            if (idTokenHint != null)
                                                            {
                                                                n.ProtocolMessage.IdTokenHint = idTokenHint.Value;
                                                            }
                                                        }

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

            app.UseResourceAuthorization(new AuthorizationManager());
        }
开发者ID:duncancave,项目名称:EmbeddedIDServer,代码行数:99,代码来源:Startup.cs

示例14: ConfigureAuth

 // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
 public void ConfigureAuth(IAppBuilder app)
 {
   app.UseResourceAuthorization(new MyWebAppAuthorization());
 }
开发者ID:tyler-technologies,项目名称:PeopleWhoMatterTrainingWebApp,代码行数:5,代码来源:Startup.Auth.cs

示例15: Configuration

        public void Configuration(IAppBuilder app)
        {
            // turn off long claims names by preventing MS JWT handler of mapping to claims types
            AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject;
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

            app.Map("/identity", idsrvApp =>
            {
                idsrvApp.UseIdentityServer(new IdentityServerOptions
                {
                    SiteName = "Embedded IdentityServer",
                    SigningCertificate = LoadCertificate(),
                    AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions
                    {
                        IdentityProviders =  ConfigureIdentityProviders,
                      EnablePostSignOutAutoRedirect = true
                    },

                    Factory = new IdentityServerServiceFactory()
                                .UseInMemoryUsers(Users.Get())
                                .UseInMemoryClients(Clients.Get())
                                .UseInMemoryScopes(Scopes.Get())
                });
            });

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            // User OpenId connect Middleware
            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                Authority = "https://localhost:44300/identity",
                ClientId = "mvc",
                Scope = "openid profile roles",
                RedirectUri = "https://localhost:44300/",
                PostLogoutRedirectUri = "https://localhost:44300/",

                ResponseType = "id_token",

                SignInAsAuthenticationType = "Cookies",
                UseTokenLifetime = false,

                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenValidated = async n =>
                    {
                        var id = n.AuthenticationTicket.Identity;

                        //if (id.FindFirst("idp").Value == "okta")
                        //    return;

                        // we want to keep first name, last name, subject and roles
                        var givenName = id.FindFirst(Constants.ClaimTypes.GivenName);
                        var familyName = id.FindFirst(Constants.ClaimTypes.FamilyName);
                        var sub = id.FindFirst(Constants.ClaimTypes.Subject);
                        var roles = id.FindAll(Constants.ClaimTypes.Role);

                        // create new identity and set name and role claim type
                        var nid = new ClaimsIdentity(
                            id.AuthenticationType,
                            Constants.ClaimTypes.GivenName,
                            Constants.ClaimTypes.Role);

                        nid.AddClaim(givenName);
                        nid.AddClaim(familyName);
                        nid.AddClaim(sub);
                        nid.AddClaims(roles);

                        // add some other app specific claim
                        nid.AddClaim(new Claim("app_specific", "some data"));
                        // keep the id_token for logout
                        nid.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken));

                        n.AuthenticationTicket = new AuthenticationTicket(nid, n.AuthenticationTicket.Properties);

                    },
                    RedirectToIdentityProvider = n =>
                    {
                        if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
                        {
                            var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");

                            if (idTokenHint != null)
                            {
                                n.ProtocolMessage.IdTokenHint = idTokenHint.Value;
                            }
                        }

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

            app.UseResourceAuthorization(new AuthorizationManager());
        }
开发者ID:eknowledger,项目名称:IdentityServer3Labs,代码行数:98,代码来源:Startup.cs


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