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 core 使用IdentityServer4的Swagger UI授权返回无效的重定向uri_Asp.net Core_Swagger_Identityserver4_Swagger Ui_Swashbuckle - Fatal编程技术网

Asp.net core 使用IdentityServer4的Swagger UI授权返回无效的重定向uri

Asp.net core 使用IdentityServer4的Swagger UI授权返回无效的重定向uri,asp.net-core,swagger,identityserver4,swagger-ui,swashbuckle,Asp.net Core,Swagger,Identityserver4,Swagger Ui,Swashbuckle,我正在使用IdentityServer使用Swashback进行虚张声势授权。我遵循以下步骤: 这是IdentityServer中的日志记录: 2019-01-17 19:17:41.031 +01:00 [ERR] Invalid redirect_uri: http://localhost:3200/oauth2-redirect.html { "ClientId": "demo_api_swagger", "ClientName": "Swagger UI for API",

我正在使用IdentityServer使用Swashback进行虚张声势授权。我遵循以下步骤:

这是IdentityServer中的日志记录:

2019-01-17 19:17:41.031 +01:00 [ERR] Invalid redirect_uri: 
http://localhost:3200/oauth2-redirect.html
{
  "ClientId": "demo_api_swagger",
  "ClientName": "Swagger UI for API",
  "AllowedRedirectUris": [
    "http://localhost:5001/oauth2-redirect.html"
  ],
  "SubjectId": "anonymous",
  "RequestedScopes": "",
  "Raw": {
    "response_type": "token",
    "client_id": "demo_api_swagger",
    "redirect_uri": "http://localhost:3200/oauth2-redirect.html",
    "scope": "api_data openid profile",
    "state": "VGh1IEph etc.."
  }
}
日志记录显示:

Invalid redirect_uri: http://localhost:3200/oauth2-redirect.html

但是我没有把这个地址放在任何地方,也不知道它从哪里来。如何设置重定向的正确地址

它来自Identity Server 4端的
客户端的配置。在文章示例中,它被设置为
http://localhost:5001/oauth2-redirect.html
,因此将其更改为适合您的内容:

new Client {
    ClientId = "demo_api_swagger",
    ClientName = "Swagger UI for demo_api",
    AllowedGrantTypes = GrantTypes.Implicit,
    AllowAccessTokensViaBrowser = true,
    RedirectUris = {"http://localhost:5001/oauth2-redirect.html"},
    AllowedScopes = {"demo_api"}
};

端口3200的重定向地址硬编码到Swigger UI中

幸运的是,有一个简单的解决方法,将键
oauth2RedirectUrl
添加到Swagger初始化中

Swaggerinit.js(添加到
wwwroot/assets
文件夹中):

Startup.cs:

app.UseSwaggerUI(options =>
{
    options.RoutePrefix = string.Empty;

    ...

    options.InjectJavascript("../assets/swaggerinit.js");
});

这适用于Swashback.AspNetCore.SwaggerUI,版本=4.0.1.0。

问题是我的配置与此代码完全相同。我需要找到的配置中可能有一些细微的差异。@MartinStaufcik是的,除了你在不同的端口上托管了你的配置
http://localhost:3200/oauth2-重定向.html
以避免查看错误,因此请更改为正确的主机端口值<代码>5001=3200
app.UseSwaggerUI(options =>
{
    options.RoutePrefix = string.Empty;

    ...

    options.InjectJavascript("../assets/swaggerinit.js");
});