Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Altinn2-generated tokens #322

Merged
merged 7 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions src/Altinn.Broker.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,38 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config

services.ConfigureHangfire();

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
var altinnOptions = new AltinnOptions();
config.GetSection(nameof(AltinnOptions)).Bind(altinnOptions);
options.SaveToken = true;
options.MetadataAddress = altinnOptions.OpenIdWellKnown;
options.TokenValidationParameters = new TokenValidationParameters
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidateAudience = false,
RequireExpirationTime = true,
ValidateLifetime = !hostEnvironment.IsDevelopment(), // Do not validate lifetime in tests
ClockSkew = TimeSpan.Zero
};
});
var altinnOptions = new AltinnOptions();
config.GetSection(nameof(AltinnOptions)).Bind(altinnOptions);
options.SaveToken = true;
options.MetadataAddress = altinnOptions.OpenIdWellKnown;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidateAudience = false,
RequireExpirationTime = true,
ValidateLifetime = !hostEnvironment.IsDevelopment(), // Do not validate lifetime in tests
ClockSkew = TimeSpan.Zero
};
})
.AddJwtBearer("Legacy", options => { // To support "overgangslosningen"
var altinnOptions = new AltinnOptions();
config.GetSection(nameof(AltinnOptions)).Bind(altinnOptions);
options.SaveToken = true;
options.MetadataAddress = altinnOptions.LegacyOpenIdWellKnown;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidateAudience = false,
RequireExpirationTime = true,
ValidateLifetime = !hostEnvironment.IsDevelopment(), // Do not validate lifetime in tests
ClockSkew = TimeSpan.Zero
};
});

services.AddTransient<IAuthorizationHandler, ScopeAccessHandler>();
services.AddAuthorization(options =>
Expand Down
1 change: 1 addition & 0 deletions src/Altinn.Broker.API/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"AltinnOptions": {
"OpenIdWellKnown": "https://platform.tt02.altinn.no/authentication/api/v1/openid/.well-known/openid-configuration",
"LegacyOpenIdWellKnown": "https://test.maskinporten.no/.well-known/oauth-authorization-server",
"PlatformGatewayUrl": "https://platform.tt02.altinn.no/",
"PlatformSubscriptionKey": ""
}
Expand Down
1 change: 1 addition & 0 deletions src/Altinn.Broker.Core/Options/AltinnOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class AltinnOptions
{
public string OpenIdWellKnown { get; set; }
public string LegacyOpenIdWellKnown { get; set; }
public string PlatformGatewayUrl { get; set; }
public string PlatformSubscriptionKey { get; set; }
}
Loading