Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oauth 2.0 IdentityServer4+;Web Api+;在一个项目中一起进行水疗_Oauth 2.0_Asp.net Core_Claims Based Identity_Openid Connect_Identityserver4 - Fatal编程技术网

Oauth 2.0 IdentityServer4+;Web Api+;在一个项目中一起进行水疗

Oauth 2.0 IdentityServer4+;Web Api+;在一个项目中一起进行水疗,oauth-2.0,asp.net-core,claims-based-identity,openid-connect,identityserver4,Oauth 2.0,Asp.net Core,Claims Based Identity,Openid Connect,Identityserver4,我很难建立一个单一的项目,所有这些东西都能很好地结合在一起 温泉 静态文件 Web API(MVC) 虚张声势 标识服务器4 IdentityServer 4.A网络身份 IdentityServer4.EntityFramework 社交登录 我从IdentityServer4.Samples\Quickstart6\u网络身份代码开始,一个接一个的集成nuget // spa app.UseDefaultFiles();

我很难建立一个单一的项目,所有这些东西都能很好地结合在一起

  • 温泉
    • 静态文件
  • Web API(MVC)
    • 虚张声势
  • 标识服务器4
    • IdentityServer 4.A网络身份
    • IdentityServer4.EntityFramework
    • 社交登录
我从IdentityServer4.Samples\Quickstart6\u网络身份代码开始,一个接一个的集成nuget

            // spa
            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseCors("any");

            // api
            app.Map(new PathString("/api"), map =>
            {
                map.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
                {
                    Authority = PublicHostUri,
                    ScopeName = ScopeName,
                    ScopeSecret = "secret",

                    RequireHttpsMetadata = PublicHostUri.ToLower().StartsWith("https"),
                    SaveToken = true,
                    EnableCaching = true
                });

                map.UseMvc();

            });
                // sts
                JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

                app.UseIdentity();
                app.UseIdentityServer();

                // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
                app.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    AuthenticationScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,

                    AutomaticAuthenticate = false,
                    AutomaticChallenge = false
                });

                app.UseTwitterAuthentication(new TwitterOptions
                {
                    ConsumerKey = "6XaCTaLbMqfj6ww3zvZ5g",
                    ConsumerSecret = "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI"
                });

                app.UseGoogleAuthentication(new GoogleOptions
                {
                    AuthenticationScheme = "Google",
                    DisplayName = "Google",
                    SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,

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

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

            app.UseSwagger();
            app.UseSwaggerUi();
我正在努力隔离Web API部分,以确保承载身份验证方案是/API管道中唯一活动的身份验证

现在,所有添加的身份验证方案,如Cookies、Google、Twitter、OIDC、Bear都用于/api路由

我错过了什么?为什么/api不仅使用UseIdentityServer身份验证或承载令牌方案


更新:我已在此处共享了有效的概念验证代码

您不能使用
映射到分支应用程序。它仅适用于指定的路径。尝试使用
MapWhen

        // api
        app.MapWhen(context => context.Request.Path.Value.StartsWith("/api"), builder=>
        {
            builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority = PublicHostUri,
                ScopeName = ScopeName,
                ScopeSecret = "secret",

                RequireHttpsMetadata = PublicHostUri.ToLower().StartsWith("https"),
                SaveToken = true,
                EnableCaching = true
            });

            builder.UseMvc();

        });

您不能使用
映射到分支应用程序。它仅适用于指定的路径。尝试使用
MapWhen

        // api
        app.MapWhen(context => context.Request.Path.Value.StartsWith("/api"), builder=>
        {
            builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority = PublicHostUri,
                ScopeName = ScopeName,
                ScopeSecret = "secret",

                RequireHttpsMetadata = PublicHostUri.ToLower().StartsWith("https"),
                SaveToken = true,
                EnableCaching = true
            });

            builder.UseMvc();

        });

您好,您是否能够构建由IdentityServer4保护的web api,该api可用于个人帐户和社交登录?如果是,我将非常感谢您的帮助:(是的,我的概念验证代码与您描述的完全一致。您想知道什么?谢谢,您能帮我回答我的问题吗?您好,您是否能够使用IdentityServer4构建web api,该api可用于个人帐户和社交登录?如果是,我将非常感谢您的帮助:(是的,我的概念验证代码和你描述的完全一样。你想知道什么?谢谢,你能帮我回答我的问题吗?