Skip to content

Commit

Permalink
add support for ver2 and test #34
Browse files Browse the repository at this point in the history
  • Loading branch information
erlendoksvoll committed Jun 26, 2023
1 parent fc37cef commit 9ae2e65
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Dan.Core/Config/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ public static string GetConsentRedirectUrl(string accreditationId, string hmac)
/// </summary>
public static string MaskinportenUrl => GetSetting("MaskinportenUrl");

/// <summary>
/// Gets the Base URL to an auxiliary Maskinporten environment
/// </summary>
public static string MaskinportenAuxUrl => GetSetting("MaskinportenAuxUrl");

/// <summary>
/// Gets setting for whether or not to use altinn servers in test mode (for profiling and problem solving)
/// </summary>
Expand All @@ -364,6 +369,11 @@ public static string GetConsentRedirectUrl(string accreditationId, string hmac)
/// </summary>
public static string MaskinportenWellknownUrl => GetSetting("MaskinportenWellknownUrl");

/// <summary>
/// Gets the url to the wellknown endpoint for the auxiliary Maskinporten env
/// </summary>
public static string MaskinportenAuxWellknownUrl => GetSetting("MaskinportenAuxWellknownUrl");

public static string AltinnWellknownUrl => GetSetting("AltinnWellknownUrl");

public const int MaxReferenceLength = 50;
Expand Down
36 changes: 36 additions & 0 deletions Dan.Core/Middleware/AuthenticationMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public class AuthenticationMiddleware : IFunctionsWorkerMiddleware
public const string DefaultScope = "altinn:dataaltinnno";

private static readonly object CmLockMaskinporten = new();
private static readonly object CmLockMaskinportenAux = new();
private static readonly object CmLockAltinnPlatform = new();
private static volatile ConfigurationManager<OpenIdConnectConfiguration>? _cmMaskinporten;
private static volatile ConfigurationManager<OpenIdConnectConfiguration>? _cmMaskinportenAux;
private static volatile ConfigurationManager<OpenIdConnectConfiguration>? _cmAltinnPlatform;

/// <summary>
Expand Down Expand Up @@ -57,6 +59,37 @@ public static ConfigurationManager<OpenIdConnectConfiguration> CmMaskinporten
}
}

/// <summary>
/// Gets or sets maskinporten aux env ConfigManager in order to support ver2 and test for a period of time
/// </summary>
public static ConfigurationManager<OpenIdConnectConfiguration> CmMaskinportenAux
{
get
{
if (_cmMaskinportenAux != null) return _cmMaskinportenAux;
lock (CmLockMaskinportenAux)
{
if (_cmMaskinportenAux == null)
{
_cmMaskinportenAux = new ConfigurationManager<OpenIdConnectConfiguration>(
Settings.MaskinportenAuxWellknownUrl,
new OpenIdConnectConfigurationRetriever(),
new HttpClient { Timeout = TimeSpan.FromMilliseconds(10000) });
}
}

return _cmMaskinportenAux;
}

set
{
lock (CmLockMaskinportenAux)
{
_cmMaskinportenAux = value;
}
}
}

/// <summary>
/// Gets or sets Altinn3 ConfigManager
/// </summary>
Expand Down Expand Up @@ -175,6 +208,9 @@ private async Task<ClaimsPrincipal> ValidateJwt(string token)
if (jwt.Issuer == Settings.MaskinportenUrl)
{
discoveryDocument = await CmMaskinporten.GetConfigurationAsync();
} else if (!string.IsNullOrEmpty(Settings.MaskinportenAuxWellknownUrl) && jwt.Issuer == Settings.MaskinportenAuxWellknownUrl)
{
discoveryDocument = await CmMaskinportenAux.GetConfigurationAsync();
}
else
{
Expand Down

0 comments on commit 9ae2e65

Please sign in to comment.