Skip to content

Commit 7581c3b

Browse files
authored
Merge pull request #1913 from navikt/legg-til-auth-for-frikort
Legg til azure auth for frikort
2 parents 316e4f7 + 97d1da0 commit 7581c3b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

web/src/main/kotlin/no/nav/su/se/bakover/web/AuthenticationConfig.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,24 @@ internal fun Application.configureAuthentication(
9595
}
9696
}
9797
}
98+
jwt("frikort2") {
99+
verifier(jwkProvider, azureAd.issuer)
100+
realm = "su-se-bakover"
101+
validate { credentials ->
102+
try {
103+
requireNotNull(credentials.payload.audience) { "Auth: Missing audience in token" }
104+
require(credentials.payload.audience.any { it == applicationConfig.azure.clientId }) {
105+
"Auth: Valid audience not found in claims"
106+
}
107+
require(getGroupsFromJWT(applicationConfig, credentials).any { it == "frikort" }) {
108+
"Auth: Valid group not found in claims. Required: [frikort]"
109+
}
110+
JWTPrincipal(credentials.payload)
111+
} catch (e: Throwable) {
112+
log.debug("Auth: Validation error during authentication", e)
113+
null
114+
}
115+
}
116+
}
98117
}
99118
}

web/src/main/kotlin/no/nav/su/se/bakover/web/Routes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal fun Application.setupKtorRoutes(
5757
distribuerDokumentService: DistribuerDokumentService,
5858
) {
5959
routing {
60-
authenticate("frikort") {
60+
authenticate("frikort", "frikort2") {
6161
frikortVedtakRoutes(services.vedtakService, clock)
6262
}
6363

0 commit comments

Comments
 (0)