|
1 | 1 | /*
|
2 |
| - * Copyright 2020-2024 the original author or authors. |
| 2 | + * Copyright 2020-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -137,6 +137,25 @@ public Authentication authenticate(Authentication authentication) throws Authent
|
137 | 137 | // In https://www.rfc-editor.org/rfc/rfc8628.html#section-3.5,
|
138 | 138 | // the following error codes are defined:
|
139 | 139 |
|
| 140 | + // expired_token |
| 141 | + // The "device_code" has expired, and the device authorization |
| 142 | + // session has concluded. The client MAY commence a new device |
| 143 | + // authorization request but SHOULD wait for user interaction before |
| 144 | + // restarting to avoid unnecessary polling. |
| 145 | + if (deviceCode.isExpired()) { |
| 146 | + if (!deviceCode.isInvalidated()) { |
| 147 | + // Invalidate the device code |
| 148 | + authorization = OAuth2Authorization.from(authorization).invalidate(deviceCode.getToken()).build(); |
| 149 | + this.authorizationService.save(authorization); |
| 150 | + if (this.logger.isWarnEnabled()) { |
| 151 | + this.logger.warn(LogMessage.format("Invalidated device code used by registered client '%s'", |
| 152 | + authorization.getRegisteredClientId())); |
| 153 | + } |
| 154 | + } |
| 155 | + OAuth2Error error = new OAuth2Error(EXPIRED_TOKEN, null, DEVICE_ERROR_URI); |
| 156 | + throw new OAuth2AuthenticationException(error); |
| 157 | + } |
| 158 | + |
140 | 159 | // authorization_pending
|
141 | 160 | // The authorization request is still pending as the end user hasn't
|
142 | 161 | // yet completed the user-interaction steps (Section 3.3). The
|
@@ -165,23 +184,6 @@ public Authentication authenticate(Authentication authentication) throws Authent
|
165 | 184 | throw new OAuth2AuthenticationException(error);
|
166 | 185 | }
|
167 | 186 |
|
168 |
| - // expired_token |
169 |
| - // The "device_code" has expired, and the device authorization |
170 |
| - // session has concluded. The client MAY commence a new device |
171 |
| - // authorization request but SHOULD wait for user interaction before |
172 |
| - // restarting to avoid unnecessary polling. |
173 |
| - if (deviceCode.isExpired()) { |
174 |
| - // Invalidate the device code |
175 |
| - authorization = OAuth2Authorization.from(authorization).invalidate(deviceCode.getToken()).build(); |
176 |
| - this.authorizationService.save(authorization); |
177 |
| - if (this.logger.isWarnEnabled()) { |
178 |
| - this.logger.warn(LogMessage.format("Invalidated device code used by registered client '%s'", |
179 |
| - authorization.getRegisteredClientId())); |
180 |
| - } |
181 |
| - OAuth2Error error = new OAuth2Error(EXPIRED_TOKEN, null, DEVICE_ERROR_URI); |
182 |
| - throw new OAuth2AuthenticationException(error); |
183 |
| - } |
184 |
| - |
185 | 187 | if (this.logger.isTraceEnabled()) {
|
186 | 188 | this.logger.trace("Validated device token request parameters");
|
187 | 189 | }
|
|
0 commit comments