Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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

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
Asp.net mvc 使用Identity Server 4 asp.net core 2.2实现Swagger授权_Asp.net Mvc_Asp.net Core_Oauth 2.0_Swagger_Identityserver4 - Fatal编程技术网

Asp.net mvc 使用Identity Server 4 asp.net core 2.2实现Swagger授权

Asp.net mvc 使用Identity Server 4 asp.net core 2.2实现Swagger授权,asp.net-mvc,asp.net-core,oauth-2.0,swagger,identityserver4,Asp.net Mvc,Asp.net Core,Oauth 2.0,Swagger,Identityserver4,正在尝试使用identity server 4实现Swagger授权。有错误,但不知道哪里做错了 身份服务器设置 public IEnumerable<Client> GetClients() { var client = new List<Client> { new Client { ClientId = ConstantValue.ClientId

正在尝试使用identity server 4实现Swagger授权。有错误,但不知道哪里做错了

身份服务器设置

public IEnumerable<Client> GetClients()
    {
        var client = new List<Client>
        {
            new Client
            {
                 ClientId = ConstantValue.ClientId,
                ClientName = ConstantValue.ClientName,
                AllowedGrantTypes = GrantTypes.Implicit,
                AllowAccessTokensViaBrowser = true,
                RequireConsent = false,
                RedirectUris =           { string.Format("{0}/{1}", Configuration["IdentityServerUrls:ClientUrl"], "assets/oidc-login-redirect.html"), string.Format("{0}/{1}", Configuration["IdentityServerUrls:ClientUrl"], "assets/silent-redirect.html") },
                PostLogoutRedirectUris = { string.Format("{0}?{1}", Configuration["IdentityServerUrls:ClientUrl"] , "postLogout=true") },
                AllowedCorsOrigins =     { Configuration["IdentityServerUrls: ClientUrl"] },

                AllowedScopes =
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    ConstantValue.ClientDashApi
                },
                IdentityTokenLifetime=120,
                AccessTokenLifetime=120
            },
            new Client
            {
                ClientId = "swaggerui",
                ClientName = "Swagger UI",
                AllowedGrantTypes = GrantTypes.Implicit,
                AllowAccessTokensViaBrowser = true,

                RedirectUris =
                {
                    string.Format("{0}/{1}", Configuration["IdentityServerUrls:ClientApiUrl"], "swagger/oauth2-redirect.html"),
                    string.Format("{0}/{1}", Configuration["IdentityServerUrls:ClientApiUrl"], "swagger/o2c.html")
                },
                AllowedCorsOrigins =     { Configuration["IdentityServerUrls: ClientApiUrl"] },

                AllowedScopes = {ConstantValue.ClientDashApi},
            },
        };
        return client;
    }
这就是我在控制台中遇到的错误。 在浏览器上

参考文献


使用
重定向URI={string.Format({0}/{1})、配置[“IdentityServerUrls:ClientUrl”]、“swagger/o2c.html”)}
客户端配置重定向URI,这将生成
http://localhost:4200/swagger/o2c.html
。但是对于您的请求,它会发送带有
http://localhost:44333/swagger/oauth2-重定向.html

尝试检查您的客户端配置并将其更改为
http://localhost:4200/swagger/o2c.html

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
    {            
        RedirectUri = "http://localhost:4200/swagger/o2c.html",
    });

由于未经授权的客户端,发出用于访问web api的令牌的请求失败。检查api项目中的客户端详细信息是否正确。我现在可以登录了。但在登录后,页面不会重定向到swagger api页面。但登录后,页面不会重定向。你能告诉我吗?@SanJaisy你以前的问题解决了吗?在我的记忆中,您最初的问题与
重定向url
有关。我已解决无效的url问题。现在我可以成功地使用identity server登录。但无法重定向回大摇大摆的用户界面。将错误获取为above@SanJaisy请接受答案,如果它解决了您的问题,或与我们共享您的解决方案,并为您的新问题重新发布新线程。请避免编辑您的原始文章,这将标记建议混乱。
http://localhost:44305/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fresponse_type%3Dtoken%26client_id%3Dswaggerui%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A44333%252Fswagger%252Foauth2-redirect.html%26scope%3Dmero-rental-client-api%26state%3DV2VkIEphbiAwOSAyMDE5IDE0OjUzOjMzIEdNVCsxMTAwIChBdXN0cmFsaWFuIEVhc3Rlcm4gRGF5bGlnaHQgVGltZSk%253D
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
    {            
        RedirectUri = "http://localhost:4200/swagger/o2c.html",
    });