Skip to content

Commit 68d1691

Browse files
committed
Merge branch '1.1.x'
Closes gh-1474
2 parents f003d7e + fb9a13b commit 68d1691

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/authentication/OidcLogoutAuthenticationProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
9797
}
9898

9999
OAuth2Authorization.Token<OidcIdToken> authorizedIdToken = authorization.getToken(OidcIdToken.class);
100-
if (!authorizedIdToken.isActive()) {
100+
if (authorizedIdToken.isInvalidated() ||
101+
authorizedIdToken.isBeforeUse()) { // Expired ID Token should be accepted
101102
throwError(OAuth2ErrorCodes.INVALID_TOKEN, "id_token_hint");
102103
}
103104

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/oidc/authentication/OidcLogoutAuthenticationProviderTests.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.junit.jupiter.api.Test;
3131

3232
import org.springframework.security.authentication.TestingAuthenticationToken;
33+
import org.springframework.security.core.Authentication;
3334
import org.springframework.security.core.session.SessionInformation;
3435
import org.springframework.security.core.session.SessionRegistry;
3536
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
@@ -134,7 +135,7 @@ public void authenticateWhenIdTokenNotFoundThenThrowOAuth2AuthenticationExceptio
134135
}
135136

136137
@Test
137-
public void authenticateWhenIdTokenNotActiveThenThrowOAuth2AuthenticationException() {
138+
public void authenticateWhenIdTokenInvalidatedThenThrowOAuth2AuthenticationException() {
138139
TestingAuthenticationToken principal = new TestingAuthenticationToken("principal", "credentials");
139140
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
140141
OidcIdToken idToken = OidcIdToken.withTokenValue("id-token")
@@ -501,6 +502,28 @@ public void authenticateWhenValidIdTokenThenAuthenticated() throws Exception {
501502
.expiresAt(Instant.now().plusSeconds(60).truncatedTo(ChronoUnit.MILLIS))
502503
.claim("sid", createHash(sessionId))
503504
.build();
505+
authenticateValidIdToken(principal, registeredClient, sessionId, idToken);
506+
}
507+
508+
// gh-1440
509+
@Test
510+
public void authenticateWhenValidExpiredIdTokenThenAuthenticated() throws Exception {
511+
TestingAuthenticationToken principal = new TestingAuthenticationToken("principal", "credentials");
512+
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
513+
String sessionId = "session-1";
514+
OidcIdToken idToken = OidcIdToken.withTokenValue("id-token")
515+
.issuer("https://provider.com")
516+
.subject(principal.getName())
517+
.audience(Collections.singleton(registeredClient.getClientId()))
518+
.issuedAt(Instant.now().minusSeconds(60).truncatedTo(ChronoUnit.MILLIS))
519+
.expiresAt(Instant.now().minusSeconds(30).truncatedTo(ChronoUnit.MILLIS)) // Expired
520+
.claim("sid", createHash(sessionId))
521+
.build();
522+
authenticateValidIdToken(principal, registeredClient, sessionId, idToken);
523+
}
524+
525+
private void authenticateValidIdToken(Authentication principal, RegisteredClient registeredClient,
526+
String sessionId, OidcIdToken idToken) {
504527
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
505528
.principalName(principal.getName())
506529
.token(idToken,

0 commit comments

Comments
 (0)