You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1166,7 +1209,9 @@ It uses an `OAuth2ErrorHttpMessageConverter` for converting the OAuth 2.0 Error
1166
1209
1167
1210
Whether you customize `DefaultOAuth2UserService` or provide your own implementation of `OAuth2UserService`, you'll need to configure it as shown in the following example:
1168
1211
1169
-
[source,java]
1212
+
====
1213
+
.Java
1214
+
[source,java,role="primary"]
1170
1215
----
1171
1216
@EnableWebSecurity
1172
1217
public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
@@ -1188,6 +1233,30 @@ public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
1188
1233
}
1189
1234
----
1190
1235
1236
+
.Kotlin
1237
+
[source,kotlin,role="secondary"]
1238
+
----
1239
+
@EnableWebSecurity
1240
+
class OAuth2LoginSecurityConfig : WebSecurityConfigurerAdapter() {
1241
+
1242
+
override fun configure(http: HttpSecurity) {
1243
+
http {
1244
+
oauth2Login {
1245
+
userInfoEndpoint {
1246
+
userService = oauth2UserService()
1247
+
// ...
1248
+
}
1249
+
}
1250
+
}
1251
+
}
1252
+
1253
+
private fun oauth2UserService(): OAuth2UserService<OAuth2UserRequest, OAuth2User> {
1254
+
// ...
1255
+
}
1256
+
}
1257
+
----
1258
+
====
1259
+
1191
1260
1192
1261
[[oauth2login-advanced-oidc-user-service]]
1193
1262
===== OpenID Connect 1.0 UserService
@@ -1200,7 +1269,9 @@ If you need to customize the pre-processing of the UserInfo Request and/or the p
1200
1269
1201
1270
Whether you customize `OidcUserService` or provide your own implementation of `OAuth2UserService` for OpenID Connect 1.0 Provider's, you'll need to configure it as shown in the following example:
1202
1271
1203
-
[source,java]
1272
+
====
1273
+
.Java
1274
+
[source,java,role="primary"]
1204
1275
----
1205
1276
@EnableWebSecurity
1206
1277
public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
@@ -1222,6 +1293,30 @@ public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
1222
1293
}
1223
1294
----
1224
1295
1296
+
.Kotlin
1297
+
[source,kotlin,role="secondary"]
1298
+
----
1299
+
@EnableWebSecurity
1300
+
class OAuth2LoginSecurityConfig : WebSecurityConfigurerAdapter() {
1301
+
1302
+
override fun configure(http: HttpSecurity) {
1303
+
http {
1304
+
oauth2Login {
1305
+
userInfoEndpoint {
1306
+
oidcUserService = oidcUserService()
1307
+
// ...
1308
+
}
1309
+
}
1310
+
}
1311
+
}
1312
+
1313
+
private fun oidcUserService(): OAuth2UserService<OidcUserRequest, OidcUser> {
1314
+
// ...
1315
+
}
1316
+
}
1317
+
----
1318
+
====
1319
+
1225
1320
1226
1321
[[oauth2login-advanced-idtoken-verify]]
1227
1322
==== ID Token Signature Verification
@@ -1237,7 +1332,9 @@ The JWS algorithm resolver is a `Function` that accepts a `ClientRegistration` a
1237
1332
1238
1333
The following code shows how to configure the `OidcIdTokenDecoderFactory` `@Bean` to default to `MacAlgorithm.HS256` for all `ClientRegistration`:
1239
1334
1240
-
[source,java]
1335
+
====
1336
+
.Java
1337
+
[source,java,role="primary"]
1241
1338
----
1242
1339
@Bean
1243
1340
public JwtDecoderFactory<ClientRegistration> idTokenDecoderFactory() {
@@ -1247,6 +1344,18 @@ public JwtDecoderFactory<ClientRegistration> idTokenDecoderFactory() {
1247
1344
}
1248
1345
----
1249
1346
1347
+
.Kotlin
1348
+
[source,kotlin,role="secondary"]
1349
+
----
1350
+
@Bean
1351
+
fun idTokenDecoderFactory(): JwtDecoderFactory<ClientRegistration?> {
1352
+
val idTokenDecoderFactory = OidcIdTokenDecoderFactory()
For MAC based algorithms such as `HS256`, `HS384` or `HS512`, the `client-secret` corresponding to the `client-id` is used as the symmetric key for signature verification.
1252
1361
@@ -1281,7 +1390,9 @@ spring:
1281
1390
1282
1391
...and the `OidcClientInitiatedLogoutSuccessHandler`, which implements RP-Initiated Logout, may be configured as follows:
1283
1392
1284
-
[source,java]
1393
+
====
1394
+
.Java
1395
+
[source,java,role="primary"]
1285
1396
----
1286
1397
@EnableWebSecurity
1287
1398
public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
@@ -1316,3 +1427,38 @@ public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
1316
1427
NOTE: `OidcClientInitiatedLogoutSuccessHandler` supports the `{baseUrl}` placeholder.
1317
1428
If used, the application's base URL, like `https://app.example.org`, will replace it at request time.
1318
1429
----
1430
+
1431
+
.Kotlin
1432
+
[source,kotlin,role="secondary"]
1433
+
----
1434
+
@EnableWebSecurity
1435
+
class OAuth2LoginSecurityConfig : WebSecurityConfigurerAdapter() {
1436
+
@Autowired
1437
+
private lateinit var clientRegistrationRepository: ClientRegistrationRepository
1438
+
1439
+
override fun configure(http: HttpSecurity) {
1440
+
http {
1441
+
authorizeRequests {
1442
+
authorize(anyRequest, authenticated)
1443
+
}
1444
+
oauth2Login { }
1445
+
logout {
1446
+
logoutSuccessHandler = oidcLogoutSuccessHandler()
1447
+
}
1448
+
}
1449
+
}
1450
+
1451
+
private fun oidcLogoutSuccessHandler(): LogoutSuccessHandler {
1452
+
val oidcLogoutSuccessHandler = OidcClientInitiatedLogoutSuccessHandler(clientRegistrationRepository)
1453
+
1454
+
// Sets the location that the End-User's User Agent will be redirected to
1455
+
// after the logout has been performed at the Provider
0 commit comments