Skip to content

Commit

Permalink
fix(oidc): allow configure auto token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Apr 28, 2022
1 parent 6f3617e commit 39da17f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Sitko.Core.Auth.IdentityServer/OidcIdentityServerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class OidcIdentityServerModule : IdentityServerModule<OidcIdentityServerM
public override string OptionsKey => "Auth:IdentityServer:Oidc";

protected override void ConfigureAuthentication(AuthenticationBuilder authenticationBuilder,
OidcIdentityServerModuleOptions startupOptions) =>
OidcIdentityServerModuleOptions startupOptions)
{
authenticationBuilder.AddOpenIdConnect(startupOptions.ChallengeScheme, options =>
{
options.SignInScheme = startupOptions.SignInScheme;
Expand All @@ -35,9 +36,14 @@ protected override void ConfigureAuthentication(AuthenticationBuilder authentica
options.Scope.Add(scope);
}
}
}).AddAutomaticTokenManagement(options =>
{
options.Scheme = startupOptions.SignInScheme;
});
if (startupOptions.AutoRefreshTokens)
{
authenticationBuilder.AddAutomaticTokenManagement(options =>
{
startupOptions.ConfigureAutoRefreshTokens?.Invoke(options);
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using FluentValidation;
using IdentityModel;
using Sitko.Core.Auth.IdentityServer.Tokens;

namespace Sitko.Core.Auth.IdentityServer
{
Expand All @@ -16,6 +18,8 @@ public class OidcIdentityServerModuleOptions : IdentityServerAuthOptions
public override bool RequiresCookie => true;
public override string SignInScheme => "Cookies";
public override string ChallengeScheme => "oidc";
public bool AutoRefreshTokens { get; set; } = true;
public Action<AutomaticTokenManagementOptions>? ConfigureAutoRefreshTokens { get; set; }
}

public class OidcAuthOptionsValidator : IdentityServerAuthOptionsValidator<OidcIdentityServerModuleOptions>
Expand Down

0 comments on commit 39da17f

Please sign in to comment.