- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个通过 Auth0 进行身份验证的 ASP.Net Core WebApi。我正在使用 Swagger 和 SwaggerUI 并尝试从 Swagger UI 进行身份验证。
// Add authentication services
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect("Auth0", options =>
{
// Set the authority to your Auth0 domain
options.Authority = $"https://{Configuration["Auth0:Authority"]}";
// Configure the Auth0 Client ID and Client Secret
options.ClientId = Configuration["Auth0:ClientId"];
options.ClientSecret = Configuration["Auth0:ClientSecret"];
// Set response type to code
options.ResponseType = "code";
// Configure the scope
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("offline_access");
options.SaveTokens = true;
// Set the callback path, so Auth0 will call back to http://localhost:3000/callback
// Also ensure that you have added the URL as an Allowed Callback URL in your Auth0 dashboard
options.CallbackPath = new PathString("/callback");
// Configure the Claims Issuer to be Auth0
options.ClaimsIssuer = "Auth0";
// Saves tokens to the AuthenticationProperties
options.SaveTokens = true;
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = context =>
{
context.ProtocolMessage.SetParameter("audience", @"https://predictor-dev.api");
return Task.FromResult(0);
},
// handle the logout redirection
OnRedirectToIdentityProviderForSignOut = (context) =>
{
var logoutUri = $"https://{Configuration["Auth0:Authority"]}/v2/logout?client_id={Configuration["Auth0:ClientId"]}";
var postLogoutUri = context.Properties.RedirectUri;
if (!string.IsNullOrEmpty(postLogoutUri))
{
if (postLogoutUri.StartsWith("/"))
{
// transform to absolute
var request = context.Request;
postLogoutUri = request.Scheme + "://" + request.Host + request.PathBase + postLogoutUri;
}
logoutUri += $"&returnTo={ Uri.EscapeDataString(postLogoutUri)}";
}
context.Response.Redirect(logoutUri);
context.HandleResponse();
return Task.CompletedTask;
}
};
})
.AddJwtBearer(options =>
{
options.Authority = Configuration["Auth0:Authority"];
options.Audience = Configuration["Auth0:Audience"];
options.TokenValidationParameters = new TokenValidationParameters
{
RoleClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/roles"
};
options.ClaimsIssuer = "Auth0";
});
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin",
builder =>
{
builder
.WithOrigins(Configuration["FrontendBaseUrl"])
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "Predictor API", Version = "v1" });
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
c.AddSecurityDefinition("oauth2", new OAuth2Scheme
{
Type = "oauth2",
Flow = "implicit",
AuthorizationUrl = $"{Configuration["Auth0:Authority"]}authorize?audience={Configuration["Auth0:Audience"]}",
Scopes = new Dictionary<string, string>
{
{ "read:books", "Access read book operations" },
{ "write:books", "Access write book operations" }
}
});
c.OperationFilter<SecurityRequirementsOperationFilter>();
});
这是通过 SwaggerUI 验证后返回的 token :
{
"iss": "my iss",
"sub": "my sub",
"aud": "my aud",
"iat": 1556002815,
"exp": 1556010015,
"azp": "azp",
"scope": "read:books"
}
这里的问题是token没有openid和profile信息。我在 Auth0 中没有任何可以限制我的范围的自定义规则(我完全删除了它们)。我尝试了不同的选项,但我无法获得任何额外的声明。
Swagger 中是否有任何我遗漏的配置?
谢谢。
最佳答案
您必须传递“openid”和“profile”范围才能使用 openid 和配置文件信息扩展您的 token
关于asp.net-core - Auth0 + Swashbuckle .Net Core 2.2。使用 SwaggerUI 时缺少 jwt token 中的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55805984/
我将 Swashbuckle.AspNetCore NuGet 添加到我的项目中,它似乎运行良好。 (我得到 Swagger 页面就好了。) 但是当我处理另一个问题(不使用 Swagger 页面)时,
.Netcore 2.2虚张声势 4.0.1 Swagger UI 在本地主机上运行,但在部署到 Azure ASE 到由应用程序网关管理的站点后,Swagger 将不会加载。 (已确认生成 sw
这是我的理解: Swagger 是一种编写文档的符号/规则。但为什么它被称为框架(如 Angular/MVC)? Swashbuckle 是一个生成文档(基于 Swagger 规则)的程序(JavaS
使用 ABP 框架 (3.3) 和 ASP.NET Core (3.1)。 在编译应用程序后,我尝试使用 Swashbuckle.AspNetCore.Cli ( https://github.com
如何在 Swashbuckle 6.0.0 的选项中禁用 Swagger Schema 验证器。我知道它在本地运行时默认关闭,但没有看到 SwaggerUI() 的 validatorURL 选项 最
我在隐藏调用时遇到 Swashbuckle 问题,链接到调用的模型定义保留在生成的 JSON 中的定义中。 使用文档过滤器,我可以从界面中删除调用。 调用保留在生成的 JSON 中,但在 Swagge
我使用 Swashbuckle 将 Swagger 文档添加到我的 ASP.NET Web API 项目中。如何在不注入(inject) CSS 的情况下从文档页面隐藏默认标题(带有 swagger
在 Swashbuckle 中,有一个名为 OrderActionGroupsBy 的设置,它应该更改 API 内的排序,但我所做的一切都不起作用,而且我无法确定这是否是 Swashbuckle 问题
我的应用程序是一个 ASP.NET Core 1.0 Web API。 我有以下 Controller : [HttpGet("{someData:MinLength(5):MaxLength
我正在尝试为 swashbuckle 注册自定义路由。但是我想不通。 我需要做的是为当前路由添加一个扩展。 举个例子:我需要将它设置为 swagger.aspx/ui 而不是 swagger/ui .
我有一个包含 90 多个表的数据库,这些表都通过外键相互交叉链接。 当我打开我的 API 的 swagger 页面时,加载需要 2 多分钟。原因似乎是它正在为每个 API 生成 Model 和 Exa
我正在使用 Swashbuckle v3.0。 我不确定这是否是一个错误,但多态性并没有像它应该的那样工作。我有以下类(class): BasePersonDocumentDto { Id,
在 ASP.NET Core webapp 中使用 Swashbuckle.AspNetCore,我们有如下响应类型: public class DateRange { [JsonConver
我正在使用 SwaggerResponse 属性来装饰我的 api Controller 操作,这一切工作正常,但是当我查看生成的文档时,参数的描述字段是空的。 是否有基于属性的方法来描述操作参数(而
我有一个 C# 对象 public class MyObject { public int property1 { get; set; } public string property2 { ge
我应该如何在 .net 核心中设置 swashbuckle 以便我可以从请求正文上传文件(多部分,表单值模型绑定(bind)已禁用)? 我尝试了什么(显然在 swashbuckle 启动配置中添加了
我从 Swashbuckle 开始,我使用 Swashbuckle 在 .NET Core 中创建了一个 Web API。 我需要在 IIS 站点的子应用程序中部署我的 API IIS 基础设施 II
是否可以在 asp.net Core 2.0 Web API 上的 Swashbuckle UI 上设置默认选中的身份验证范围复选框? 我使用“openid”范围,我希望每次都检查它。 谢谢你。 最佳
我们在代码中使用 JetBrains 注释来定义对象模型的可空性行为。默认情况下,我无法在使用 Swashbuckle.AspNetCore v5.0.0-rc5 实现的 Swagger UI 中看到
我们在代码中使用 JetBrains 注释来定义对象模型的可空性行为。默认情况下,我无法在使用 Swashbuckle.AspNetCore v5.0.0-rc5 实现的 Swagger UI 中看到
我是一名优秀的程序员,十分优秀!