How does AddClaimsToRequest
work?
#1935
-
Hi, I'm trying to figure out how AddClaimsToRequest actually works and, how I can use it in my client API? The Does anyone have some experience that they can share with me ? Thx. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You may wanna see the Claims Transformation docs firstly! When you access an API, the |
Beta Was this translation helpful? Give feedback.
-
I am facing same issue. Am I missing something? Also, when I try to access Claims in ocelot gateway middleware, then Claims are also empty. Below is my start up code: public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration);
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("my key"));
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer("TestKey", opt =>
{
opt.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = key,
ValidateAudience = false,
ValidateIssuer = false,
ValidateLifetime = true,
ClockSkew = TimeSpan.Zero,
};
});
services.AddHttpContextAccessor();
services.AddCors(opt =>
{
opt.AddPolicy("CorsPolicy", policy =>
{
policy.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin();
});
});
}
public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseMiddleware<ErrorHandlingMiddleware>();
app.UseCors("CorsPolicy");
app.UseMiddleware<RequestResponseLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseMiddleware<AuthorizationMiddleware>(Permissions);
await app.UseOcelot();
} |
Beta Was this translation helpful? Give feedback.
-
I too have the same issue: how |
Beta Was this translation helpful? Give feedback.
You may wanna see the Claims Transformation docs firstly!
if you wanna get a deep understand for how claims transform work, you may wanna have a look at the source code.
When you access an API, the
Ocelot
will check authentication, and if the user have a permission for the API. If authenticated successfully, Ocelot will get the claims of the user, and if you config ClaimsToRequest (Header/Query), the middleware will invoke after authenticated and before request the downstream.