Skip to content

Commit 44253ad

Browse files
committed
fix(oidc): providers order in map
move list to object conversion from terraform to nodejs lambdas to preserve order of the providers in the list, so the first provider defined is the default
1 parent 43af53e commit 44253ad

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

modules/oidc/lambda/callback/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const https = require('https');
44
const querystring = require('querystring');
55
const crypto = require('crypto');
66

7-
const config = JSON.parse(process.env.OIDC_CONFIG_JSON || '{}');
7+
const configList = JSON.parse(process.env.OIDC_CONFIG_JSON || '[]');
8+
const config = Object.fromEntries(configList.map(cfg => [cfg.application_name, cfg]));
89

910
exports.handler = (event, context, callback) => {
1011
//console.log('Callback Lambda - Received event:', JSON.stringify(event, null, 2));

modules/oidc/lambda/edge_auth/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
const crypto = require('crypto');
44
const querystring = require('querystring');
55

6-
const config = require('./config.json');
6+
// Load config as list and convert to map by application_name
7+
const configList = require('./config.json');
8+
const config = Object.fromEntries(configList.map(cfg => [cfg.application_name, cfg]));
79

810
exports.handler = (event, context, callback) => {
911
try {

modules/oidc/shared.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
locals {
22
enabled = length(var.oidc) > 0
33

4-
oidc_config = {
5-
for cfg in var.oidc : cfg.application_name => {
4+
oidc_config = [
5+
for cfg in var.oidc : {
6+
application_name = cfg.application_name
67
client_id = cfg.application_id
78
client_secret = cfg.client_secret
89
auth_url = cfg.auth_url
@@ -12,13 +13,13 @@ locals {
1213
redirect_after_login = "https://${var.application_domain}"
1314
session_duration = cfg.session_duration
1415
}
15-
}
16+
]
1617

1718
oidc_config_json = local.enabled ? jsonencode(local.oidc_config) : null
1819
}
1920

2021
resource "random_string" "session_secret" {
21-
count = local.enabled ? 1 : 0
22+
count = local.enabled ? 1 : 0
2223
length = 64
2324
special = true
2425
}

0 commit comments

Comments
 (0)