Skip to content

Instantly share code, notes, and snippets.

@justintoth
Created January 13, 2022 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justintoth/4f5cc4238d7a942369aef12209769004 to your computer and use it in GitHub Desktop.
Save justintoth/4f5cc4238d7a942369aef12209769004 to your computer and use it in GitHub Desktop.
private readonly OpenIdConnectPostConfigureOptions _oidcPostConfigureOptions;
private readonly IOptionsMonitorCache<OpenIdConnectOptions> _oidcOptionsCache;
private readonly OAuthPostConfigureOptions<OAuthOptions, OAuthHandler<OAuthOptions>> _oauthPostConfigureOptions;
private readonly IOptionsMonitorCache<OAuthOptions> _oauthOptionsCache;
public SsoController(
OpenIdConnectPostConfigureOptions oidcPostConfigureOptions,
IOptionsMonitorCache<OpenIdConnectOptions> oidcOptionsCache,
OAuthPostConfigureOptions<OAuthOptions, OAuthHandler<OAuthOptions>> oauthPostConfigureOptions,
IOptionsMonitorCache<OAuthOptions> oauthOptionsCache)
{
_oidcPostConfigureOptions = oidcPostConfigureOptions;
_oidcOptionsCache = oidcOptionsCache;
_oauthPostConfigureOptions = oauthPostConfigureOptions;
_oauthOptionsCache = oauthOptionsCache;
}
[HttpPost("refresh-config/{ssoIdentityProviderId:int}")]
public IActionResult RefreshConfig(int ssoIdentityProviderId)
{
var ssoIdentityProvider = SingleSignOnStore.Model.Instance.GetIdentityProvider(ssoIdentityProviderId);
if (ssoIdentityProvider == null)
return NotFound();
switch (ssoIdentityProvider.SsoFlowType)
{
case SsoFlowType.Oidc:
var oidcOptions = new OpenIdConnectOptions();
StartupSsoExtensions.SetOidcOptions(ssoIdentityProvider, oidcOptions);
_oidcPostConfigureOptions.PostConfigure(ssoIdentityProvider.SsoCode, oidcOptions);
_oidcOptionsCache.TryRemove(ssoIdentityProvider.SsoCode);
_oidcOptionsCache.TryAdd(ssoIdentityProvider.SsoCode, oidcOptions);
break;
case SsoFlowType.OAuth2:
var oauth2Options = new OAuthOptions();
StartupSsoExtensions.SetOAuth2Options(ssoIdentityProvider, oauth2Options);
_oauthPostConfigureOptions.PostConfigure(ssoIdentityProvider.SsoCode, oauth2Options);
_oauthOptionsCache.TryRemove(ssoIdentityProvider.SsoCode);
_oauthOptionsCache.TryAdd(ssoIdentityProvider.SsoCode, oauth2Options);
break;
/*case SsoFlowType.SamlNew:
var samlOptions = new OAuthOptions();
StartupSsoExtensions.SetSamlOptions(ssoIdentityProvider, samlOptions);
_samlPostConfigureOptions.PostConfigure(ssoIdentityProvider.SsoCode, samlOptions);
break;*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment