Skip to content

Commit 49a51ff

Browse files
committed
Entra ID compatibility
1 parent e0ebbb0 commit 49a51ff

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/main/kotlin/fi/hsl/jore4/auth/oidc/OIDCCodeExchangeService.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fi.hsl.jore4.auth.oidc
22

33
import com.nimbusds.oauth2.sdk.AuthorizationCode
44
import com.nimbusds.oauth2.sdk.AuthorizationCodeGrant
5+
import com.nimbusds.oauth2.sdk.Scope
56
import com.nimbusds.oauth2.sdk.TokenRequest
67
import com.nimbusds.oauth2.sdk.auth.ClientSecretBasic
78
import com.nimbusds.oauth2.sdk.auth.Secret
@@ -61,7 +62,8 @@ open class OIDCCodeExchangeService(
6162
TokenRequest(
6263
oidcProviderMetadataSupplier.providerMetadata.tokenEndpointURI,
6364
ClientSecretBasic(ClientID(oidcProperties.clientId), Secret(oidcProperties.clientSecret)),
64-
AuthorizationCodeGrant(code, callbackUri)
65+
AuthorizationCodeGrant(code, callbackUri),
66+
Scope("openid")
6567
)
6668
val response = OIDCTokenResponseParser.parse(request.toHTTPRequest().send())
6769

@@ -77,8 +79,10 @@ open class OIDCCodeExchangeService(
7779
val accessToken = successResponse.oidcTokens.accessToken
7880
val refreshToken = successResponse.oidcTokens.refreshToken
7981

80-
// verify token authenticity and validity
81-
verificationService.parseAndVerifyAccessToken(accessToken)
82+
// verify token authenticity and validity if not using Entra
83+
if (!oidcProperties.providerBaseUrl.startsWith("https://login.microsoftonline.com/")) {
84+
verificationService.parseAndVerifyAccessToken(accessToken)
85+
}
8286

8387
session.setAttribute(SessionKeys.USER_TOKEN_SET_KEY, UserTokenSet(accessToken, refreshToken))
8488

src/main/kotlin/fi/hsl/jore4/auth/oidc/TokenVerificationService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ open class TokenVerificationService(
5252
ClientID(oidcProperties.clientId),
5353
Secret(oidcProperties.clientSecret)
5454
)
55-
// retry to verify the new access token
56-
parseAndVerifyAccessToken(newTokenSet.accessToken)
55+
// retry to verify the new access token if not using Entra
56+
if (!oidcProperties.providerBaseUrl.startsWith("https://login.microsoftonline.com/")) {
57+
parseAndVerifyAccessToken(newTokenSet.accessToken)
58+
}
5759
newTokenSet
5860
}
5961

src/main/kotlin/fi/hsl/jore4/auth/oidc/UserTokenSet.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fi.hsl.jore4.auth.oidc
22

33
import com.nimbusds.oauth2.sdk.RefreshTokenGrant
4+
import com.nimbusds.oauth2.sdk.Scope
45
import com.nimbusds.oauth2.sdk.TokenRequest
56
import com.nimbusds.oauth2.sdk.TokenResponse
67
import com.nimbusds.oauth2.sdk.auth.ClientSecretBasic
@@ -39,7 +40,8 @@ class UserTokenSet(
3940
TokenRequest(
4041
tokenEndpointURI,
4142
ClientSecretBasic(clientID, clientSecret),
42-
RefreshTokenGrant(refreshToken)
43+
RefreshTokenGrant(refreshToken),
44+
Scope("openid")
4345
)
4446

4547
val response = TokenResponse.parse(request.toHTTPRequest().send())

0 commit comments

Comments
 (0)