Попытка внедрить Swagger Authorization с сервером идентификации 4. Получаю ошибки, но не знаю, где я делаю неправильно.
Настройка Identity Server
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;
}
API-коды
services.AddSwaggerGen(options =>
{
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
{
Type = "oauth2",
Flow = "implicit",
AuthorizationUrl = "http://localhost:44305/connect/authorize",
TokenUrl = "http://localhost:44305/connect/token",
Scopes = new Dictionary<string, string>()
{
{ "mero-rental-client-api", "mero-rental-client-api" }
}
});
});
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Mero Rental API V1");
options.OAuthClientId("swaggerui");
options.OAuthAppName("Swagger UI");
});
Это URL перенаправления
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
Это ошибка, которую я получаю в консоли.
В браузере.
Ссылки
https://www.scottbrady91.com/Identity-Server/ASPNET-Core-Swagger-UI-Authorization-using-IdentityServer4
https://dave.vanherten.ca/2017/03/swagger-identityserver4-part2/