Skip to content

Commit

Permalink
merge hotfix 0.3.15
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Mar 16, 2022
2 parents d0824e5 + 78a3f31 commit fcc997a
Show file tree
Hide file tree
Showing 3 changed files with 12,227 additions and 1,939 deletions.
8 changes: 6 additions & 2 deletions src/EthernaSSO/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
using Hangfire.Mongo.Migration.Strategies;
using Hangfire.Mongo.Migration.Strategies.Backup;
using IdentityServer4.Stores;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization.Infrastructure;
Expand Down Expand Up @@ -123,14 +125,16 @@ public void ConfigureServices(IServiceCollection services)
options.SlidingExpiration = true;

// Response 401 for unauthorized call on api.
options.Events.OnRedirectToLogin = context =>
static Task unauthorizedApiCallHandler(RedirectContext<CookieAuthenticationOptions> context)
{
if (context.Request.Path.StartsWithSegments("/api", StringComparison.InvariantCulture))
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
else
context.Response.Redirect(context.RedirectUri);
return Task.CompletedTask;
};
}
options.Events.OnRedirectToAccessDenied = unauthorizedApiCallHandler;
options.Events.OnRedirectToLogin = unauthorizedApiCallHandler;
});

services.Configure<ForwardedHeadersOptions>(options =>
Expand Down
Loading

0 comments on commit fcc997a

Please sign in to comment.