プロトコルエンドポイント

OAuth2 認証エンドポイント

OAuth2AuthorizationEndpointConfigurer は、OAuth2 認証エンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 認可リクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2AuthorizationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.authorizationEndpoint(authorizationEndpoint ->
					authorizationEndpoint
        				.authorizationRequestConverter(authorizationRequestConverter)   (1)
                        .authorizationRequestConverters(authorizationRequestConvertersConsumer) (2)
                        .authenticationProvider(authenticationProvider) (3)
                        .authenticationProviders(authenticationProvidersConsumer)   (4)
                        .authorizationResponseHandler(authorizationResponseHandler) (5)
                        .errorResponseHandler(errorResponseHandler) (6)
                        .consentPage("/oauth2/v1/authorize")    (7)
				)
		);

	return http.build();
}
1authorizationRequestConverter()HttpServletRequest から OAuth2 認可リクエスト [IETF] (英語) (または同意) を OAuth2AuthorizationCodeRequestAuthenticationToken または OAuth2AuthorizationConsentAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。
2authorizationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2AuthorizationCodeRequestAuthenticationToken または OAuth2AuthorizationConsentAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5authorizationResponseHandler(): 「認証された」 OAuth2AuthorizationCodeRequestAuthenticationToken を処理し、OAuth2AuthorizationResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthorizationCodeRequestAuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。
7consentPage(): 認可リクエストフロー中に同意が必要な場合にリソース所有者をリダイレクトするカスタム同意ページの URI

OAuth2AuthorizationEndpointConfigurer は OAuth2AuthorizationEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OAuth2AuthorizationEndpointFilter は、OAuth2 認証リクエスト (および同意) を処理する Filter です。

OAuth2AuthorizationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2AuthorizationCodeRequestAuthenticationConverter と OAuth2AuthorizationConsentAuthenticationConverter で構成される DelegatingAuthenticationConverter

  • AuthenticationManager —  OAuth2AuthorizationCodeRequestAuthenticationProvider と OAuth2AuthorizationConsentAuthenticationProvider で構成される AuthenticationManager

  • AuthenticationSuccessHandler — 「認証された」 OAuth2AuthorizationCodeRequestAuthenticationToken を処理し、OAuth2AuthorizationResponse を返す内部実装。

  • AuthenticationFailureHandler —  OAuth2AuthorizationCodeRequestAuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

認可リクエスト検証のカスタマイズ

OAuth2AuthorizationCodeRequestAuthenticationValidator は、Authorization Code Grant で使用される特定の OAuth2 認可リクエストパラメーターを検証するために使用されるデフォルトのバリデータです。デフォルトの実装では、redirect_uri および scope パラメーターが検証されます。検証に失敗すると、OAuth2AuthorizationCodeRequestAuthenticationException がスローされます。

OAuth2AuthorizationCodeRequestAuthenticationProvider は、型 Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> のカスタム認証バリデーターを setAuthenticationValidator() に提供することにより、デフォルトの認可リクエストの検証をオーバーライドする機能を提供します。

OAuth2AuthorizationCodeRequestAuthenticationContext は、OAuth2 認証リクエストパラメーターを含む OAuth2AuthorizationCodeRequestAuthenticationToken を保持します。
検証が失敗した場合、認証バリデータ MUST は OAuth2AuthorizationCodeRequestAuthenticationException をスローします。

開発ライフサイクルフェーズでの一般的な使用例は、redirect_uri パラメーターで localhost を許可することです。

次の例は、redirect_uri パラメーターで localhost を許可するカスタム認証バリデータを使用して OAuth2AuthorizationCodeRequestAuthenticationProvider を構成する方法を示しています。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.authorizationEndpoint(authorizationEndpoint ->
					authorizationEndpoint
                        .authenticationProviders(configureAuthenticationValidator())
				)
		);

	return http.build();
}

private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
	return (authenticationProviders) ->
		authenticationProviders.forEach((authenticationProvider) -> {
			if (authenticationProvider instanceof OAuth2AuthorizationCodeRequestAuthenticationProvider) {
				Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> authenticationValidator =
					// Override default redirect_uri validator
					new CustomRedirectUriValidator()
						// Reuse default scope validator
						.andThen(OAuth2AuthorizationCodeRequestAuthenticationValidator.DEFAULT_SCOPE_VALIDATOR);

				((OAuth2AuthorizationCodeRequestAuthenticationProvider) authenticationProvider)
					.setAuthenticationValidator(authenticationValidator);
			}
		});
}

static class CustomRedirectUriValidator implements Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> {

	@Override
	public void accept(OAuth2AuthorizationCodeRequestAuthenticationContext authenticationContext) {
		OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthentication =
			authenticationContext.getAuthentication();
		RegisteredClient registeredClient = authenticationContext.getRegisteredClient();
		String requestedRedirectUri = authorizationCodeRequestAuthentication.getRedirectUri();

		// Use exact string matching when comparing client redirect URIs against pre-registered URIs
		if (!registeredClient.getRedirectUris().contains(requestedRedirectUri)) {
			OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST);
			throw new OAuth2AuthorizationCodeRequestAuthenticationException(error, null);
		}
	}
}

OAuth2 Pushed Authorization Request Endpoint

OAuth2PushedAuthorizationRequestEndpointConfigurer は、OAuth2 Pushed Authorization Request endpoint [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 Pushed Authorization requests [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2PushedAuthorizationRequestEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.pushedAuthorizationRequestEndpoint(pushedAuthorizationRequestEndpoint ->
					pushedAuthorizationRequestEndpoint
        				.pushedAuthorizationRequestConverter(pushedAuthorizationRequestConverter)   (1)
                        .pushedAuthorizationRequestConverters(pushedAuthorizationRequestConvertersConsumer) (2)
                        .authenticationProvider(authenticationProvider) (3)
                        .authenticationProviders(authenticationProvidersConsumer)   (4)
                        .pushedAuthorizationResponseHandler(pushedAuthorizationResponseHandler) (5)
                        .errorResponseHandler(errorResponseHandler) (6)
				)
		);

	return http.build();
}
1pushedAuthorizationRequestConverter()HttpServletRequest から OAuth2 pushed authorization request [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2PushedAuthorizationRequestAuthenticationToken のインスタンスに追加します。
2pushedAuthorizationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2PushedAuthorizationRequestAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5pushedAuthorizationResponseHandler(): 「認証された」 OAuth2PushedAuthorizationRequestAuthenticationToken を処理し、OAuth2 pushed authorization response [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。

OAuth2PushedAuthorizationRequestEndpointConfigurer configures the OAuth2PushedAuthorizationRequestEndpointFilter and registers it with the OAuth2 authorization server SecurityFilterChain @BeanOAuth2PushedAuthorizationRequestEndpointFilter is the Filter that processes OAuth2 pushed authorization requests.

OAuth2PushedAuthorizationRequestEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter — A DelegatingAuthenticationConverter composed of OAuth2AuthorizationCodeRequestAuthenticationConverter.

  • AuthenticationManager —  OAuth2PushedAuthorizationRequestAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler — An internal implementation that handles an “authenticated” OAuth2PushedAuthorizationRequestAuthenticationToken and returns the OAuth2 pushed authorization response.

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

Customizing Pushed Authorization Request Validation

OAuth2AuthorizationCodeRequestAuthenticationValidator is the default validator used for validating specific OAuth2 pushed authorization request parameters used in the Authorization Code Grant. The default implementation validates the redirect_uri and scope parameters. If validation fails, an OAuth2AuthorizationCodeRequestAuthenticationException is thrown.

OAuth2PushedAuthorizationRequestAuthenticationProvider provides the ability to override the default pushed authorization request validation by supplying a custom authentication validator of type Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> to setAuthenticationValidator().

OAuth2AuthorizationCodeRequestAuthenticationContext holds the OAuth2AuthorizationCodeRequestAuthenticationToken, which contains the OAuth2 pushed authorization request parameters.
検証が失敗した場合、認証バリデータ MUST は OAuth2AuthorizationCodeRequestAuthenticationException をスローします。

開発ライフサイクルフェーズでの一般的な使用例は、redirect_uri パラメーターで localhost を許可することです。

次の例は、redirect_uri パラメーターで localhost を許可するカスタム認証バリデータを使用して OAuth2PushedAuthorizationRequestAuthenticationProvider を構成する方法を示しています。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.pushedAuthorizationRequestEndpoint(pushedAuthorizationRequestEndpoint ->
					pushedAuthorizationRequestEndpoint
                        .authenticationProviders(configureAuthenticationValidator())
				)
		);

	return http.build();
}

private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
	return (authenticationProviders) ->
		authenticationProviders.forEach((authenticationProvider) -> {
			if (authenticationProvider instanceof OAuth2PushedAuthorizationRequestAuthenticationProvider) {
				Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> authenticationValidator =
					// Override default redirect_uri validator
					new CustomRedirectUriValidator()
						// Reuse default scope validator
						.andThen(OAuth2AuthorizationCodeRequestAuthenticationValidator.DEFAULT_SCOPE_VALIDATOR);

				((OAuth2PushedAuthorizationRequestAuthenticationProvider) authenticationProvider)
					.setAuthenticationValidator(authenticationValidator);
			}
		});
}

static class CustomRedirectUriValidator implements Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> {

	@Override
	public void accept(OAuth2AuthorizationCodeRequestAuthenticationContext authenticationContext) {
		OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthentication =
			authenticationContext.getAuthentication();
		RegisteredClient registeredClient = authenticationContext.getRegisteredClient();
		String requestedRedirectUri = authorizationCodeRequestAuthentication.getRedirectUri();

		// Use exact string matching when comparing client redirect URIs against pre-registered URIs
		if (!registeredClient.getRedirectUris().contains(requestedRedirectUri)) {
			OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST);
			throw new OAuth2AuthorizationCodeRequestAuthenticationException(error, null);
		}
	}
}

OAuth2 デバイス認証エンドポイント

OAuth2DeviceAuthorizationEndpointConfigurer は、OAuth2 デバイス認証エンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 デバイス認証リクエストの前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2DeviceAuthorizationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.deviceAuthorizationEndpoint(deviceAuthorizationEndpoint ->
                    deviceAuthorizationEndpoint
                        .deviceAuthorizationRequestConverter(deviceAuthorizationRequestConverter)   (1)
                        .deviceAuthorizationRequestConverters(deviceAuthorizationRequestConvertersConsumer) (2)
                        .authenticationProvider(authenticationProvider) (3)
                        .authenticationProviders(authenticationProvidersConsumer)   (4)
                        .deviceAuthorizationResponseHandler(deviceAuthorizationResponseHandler) (5)
                        .errorResponseHandler(errorResponseHandler) (6)
                        .verificationUri("/oauth2/v1/device_verification")  (7)
				)
		);

	return http.build();
}
1deviceAuthorizationRequestConverter()HttpServletRequest から OAuth2 デバイス認可リクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2DeviceAuthorizationRequestAuthenticationToken のインスタンスに追加します。
2deviceAuthorizationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2DeviceAuthorizationRequestAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5deviceAuthorizationResponseHandler(): 「認証された」 OAuth2DeviceAuthorizationRequestAuthenticationToken を処理し、OAuth2DeviceAuthorizationResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。
7verificationUri(): リソース所有者をセカンダリデバイスに誘導するためのカスタムエンドユーザー検証ページの URI

OAuth2DeviceAuthorizationEndpointConfigurer は OAuth2DeviceAuthorizationEndpointFilter を構成し、OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OAuth2DeviceAuthorizationEndpointFilter は、OAuth2 デバイス認証リクエストを処理する Filter です。

OAuth2DeviceAuthorizationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2DeviceAuthorizationRequestAuthenticationConverter

  • AuthenticationManager —  OAuth2DeviceAuthorizationRequestAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler — 「認証された」 OAuth2DeviceAuthorizationRequestAuthenticationToken を処理し、OAuth2DeviceAuthorizationResponse を返す内部実装。

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

OAuth2 デバイス検証エンドポイント

OAuth2DeviceVerificationEndpointConfigurer は、OAuth2 デバイス検証エンドポイント [IETF] (英語) (または「ユーザーインタラクション」) をカスタマイズする機能を提供します。OAuth2 デバイス検証リクエストの前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2DeviceVerificationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.deviceVerificationEndpoint(deviceVerificationEndpoint ->
                    deviceVerificationEndpoint
                        .deviceVerificationRequestConverter(deviceVerificationRequestConverter) (1)
                        .deviceVerificationRequestConverters(deviceVerificationRequestConvertersConsumer)   (2)
                        .authenticationProvider(authenticationProvider) (3)
                        .authenticationProviders(authenticationProvidersConsumer)   (4)
                        .deviceVerificationResponseHandler(deviceVerificationResponseHandler)   (5)
                        .errorResponseHandler(errorResponseHandler) (6)
                        .consentPage("/oauth2/v1/consent")  (7)
				)
		);

	return http.build();
}
1deviceVerificationRequestConverter()HttpServletRequest から OAuth2 デバイス検証リクエスト [IETF] (英語) (または同意) を OAuth2DeviceVerificationAuthenticationToken または OAuth2DeviceAuthorizationConsentAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。
2deviceVerificationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2DeviceVerificationAuthenticationToken または OAuth2DeviceAuthorizationConsentAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5deviceVerificationResponseHandler()AuthenticationSuccessHandler ( ポストプロセッサー ) は、「認証された」 OAuth2DeviceVerificationAuthenticationToken を処理し、リソース所有者にデバイスに戻るよう指示するために使用されます。
6errorResponseHandler()AuthenticationFailureHandler ( ポストプロセッサー ) は、OAuth2AuthenticationException を処理し、エラーレスポンスを返すために使用されます。
7consentPage(): デバイス検証リクエストフロー中に同意が必要な場合に、リソース所有者をリダイレクトするためのカスタム同意ページの URI

OAuth2DeviceVerificationEndpointConfigurer は OAuth2DeviceVerificationEndpointFilter を構成し、OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OAuth2DeviceVerificationEndpointFilter は、OAuth2 デバイス検証リクエスト (および同意) を処理する Filter です。

OAuth2DeviceVerificationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2DeviceVerificationAuthenticationConverter と OAuth2DeviceAuthorizationConsentAuthenticationConverter で構成される DelegatingAuthenticationConverter

  • AuthenticationManager —  OAuth2DeviceVerificationAuthenticationProvider と OAuth2DeviceAuthorizationConsentAuthenticationProvider で構成される AuthenticationManager

  • AuthenticationSuccessHandler — 「認証された」 OAuth2DeviceVerificationAuthenticationToken を処理し、ユーザーを成功ページ (/?success) にリダイレクトする SimpleUrlAuthenticationSuccessHandler

  • AuthenticationFailureHandler —  OAuth2AuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

OAuth2 トークンエンドポイント

OAuth2TokenEndpointConfigurer は、OAuth2 トークンエンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 アクセストークンリクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2TokenEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.tokenEndpoint(tokenEndpoint ->
                    tokenEndpoint
                        .accessTokenRequestConverter(accessTokenRequestConverter)   (1)
                        .accessTokenRequestConverters(accessTokenRequestConvertersConsumer) (2)
                        .authenticationProvider(authenticationProvider) (3)
                        .authenticationProviders(authenticationProvidersConsumer)   (4)
                        .accessTokenResponseHandler(accessTokenResponseHandler) (5)
                        .errorResponseHandler(errorResponseHandler) (6)
				)
		);

	return http.build();
}
1accessTokenRequestConverter()HttpServletRequest から OAuth2 アクセストークンリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2AuthorizationGrantAuthenticationToken のインスタンスに追加します。
2accessTokenRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2AuthorizationGrantAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5accessTokenResponseHandler()OAuth2AccessTokenAuthenticationToken を処理して OAuth2AccessTokenResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。

OAuth2TokenEndpointConfigurer は OAuth2TokenEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OAuth2TokenEndpointFilter は、OAuth2 アクセストークンリクエストを処理する Filter です。

サポートされている認可付与型 [IETF] (英語) は authorization_coderefresh_tokenclient_credentialsurn:ietf:params:oauth:grant-type:device_codeurn:ietf:params:oauth:grant-type:token-exchange です。

OAuth2TokenEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2AuthorizationCodeAuthenticationConverterOAuth2RefreshTokenAuthenticationConverterOAuth2ClientCredentialsAuthenticationConverterOAuth2DeviceCodeAuthenticationConverterOAuth2TokenExchangeAuthenticationConverter で構成される DelegatingAuthenticationConverter

  • AuthenticationManager —  OAuth2AuthorizationCodeAuthenticationProviderOAuth2RefreshTokenAuthenticationProviderOAuth2ClientCredentialsAuthenticationProviderOAuth2DeviceCodeAuthenticationProviderOAuth2TokenExchangeAuthenticationProvider で構成される AuthenticationManager

  • AuthenticationSuccessHandler —  OAuth2AccessTokenResponseAuthenticationSuccessHandler

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

クライアント認証情報の付与リクエストの検証のカスタマイズ

OAuth2ClientCredentialsAuthenticationValidator は、特定の OAuth2 クライアント資格情報付与リクエストパラメーターを検証するために使用されるデフォルトのバリデーターです。デフォルトの実装では、scope パラメーターが検証されます。検証が失敗した場合は、OAuth2AuthenticationException がスローされます。

OAuth2ClientCredentialsAuthenticationProvider は、Consumer<OAuth2ClientCredentialsAuthenticationContext> 型のカスタム認証バリデーターを setAuthenticationValidator() に提供することで、デフォルトのリクエスト検証をオーバーライドする機能を提供します。

OAuth2ClientCredentialsAuthenticationContext は、OAuth2 クライアント資格情報付与リクエストパラメーターを含む OAuth2ClientCredentialsAuthenticationToken を保持します。
検証が失敗した場合、認証バリデータ MUST は OAuth2AuthenticationException をスローします。

次の例は、デフォルトの scope 検証をオーバーライドするカスタム認証バリデータを使用して OAuth2ClientCredentialsAuthenticationProvider を設定する方法を示しています。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.tokenEndpoint(tokenEndpoint ->
                    tokenEndpoint
                        .authenticationProviders(configureAuthenticationValidator())
				)
		);

	return http.build();
}

private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
	return (authenticationProviders) ->
		authenticationProviders.forEach((authenticationProvider) -> {
			if (authenticationProvider instanceof OAuth2ClientCredentialsAuthenticationProvider) {
				Consumer<OAuth2ClientCredentialsAuthenticationContext> authenticationValidator =
					new CustomScopeValidator();

				// Override default scope validation
				((OAuth2ClientCredentialsAuthenticationProvider) authenticationProvider)
					.setAuthenticationValidator(authenticationValidator);
			}
		});
}

static class CustomScopeValidator implements Consumer<OAuth2ClientCredentialsAuthenticationContext> {

	@Override
	public void accept(OAuth2ClientCredentialsAuthenticationContext authenticationContext) {
		OAuth2ClientCredentialsAuthenticationToken clientCredentialsAuthentication =
			authenticationContext.getAuthentication();

		Set<String> requestedScopes = clientCredentialsAuthentication.getScopes();
		RegisteredClient registeredClient = authenticationContext.getRegisteredClient();
		Set<String> allowedScopes = registeredClient.getScopes();

        // TODO Implement scope validation

	}
}

DPoP バインドアクセストークン

RFC 9449 OAuth 2.0 Demonstrating Proof of Possession (DPPoP とは) [IETF] (英語) is an application-level mechanism for sender-constraining an access token.

The primary goal of DPoP is to prevent unauthorized or illegitimate clients from using leaked or stolen access tokens, by binding an access token to a public key upon issuance by the authorization server and requiring that the client proves possession of the corresponding private key when using the access token at the resource server.

Access tokens that are sender-constrained via DPoP stand in contrast to the typical bearer token, which can be used by any client in possession of the access token.

DPoP introduces the concept of a DPoP Proof [IETF] (英語) , which is a JWT created by the client and sent as a header in an HTTP request. A client uses a DPoP proof to prove the possession of a private key corresponding to a certain public key.

When the client initiates an access token request, it attaches a DPoP proof to the request in an HTTP header. The authorization server binds (sender-constrains) the access token to the public key associated in the DPoP proof.

When the client initiates a protected resource request, it again attaches a DPoP proof to the request in an HTTP header.

The resource server obtains information about the public key bound to the access token, either directly in the access token (JWT) or via the OAuth2 トークンイントロスペクションエンドポイント . The resource server then verifies that the public key bound to the access token matches the public key in the DPoP proof. It also verifies that the access token hash in the DPoP proof matches the access token in the request.

DPoP Access Token Request

To request an access token that is bound to a public key using DPoP, the client MUST provide a valid DPoP proof in the DPoP header when making an access token request to the OAuth2 Token endpoint. This is applicable for all access token requests regardless of authorization grant type (e.g. authorization_coderefresh_tokenclient_credentials, etc).

The following HTTP request shows an authorization_code access token request with a DPoP proof in the DPoP header:

POST /oauth2/token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
DPoP: eyJraWQiOiJyc2EtandrLWtpZCIsInR5cCI6ImRwb3Arand0IiwiYWxnIjoiUlMyNTYiLCJqd2siOnsia3R5IjoiUlNBIiwiZSI6IkFRQUIiLCJraWQiOiJyc2EtandrLWtpZCIsIm4iOiIzRmxxSnI1VFJza0lRSWdkRTNEZDdEOWxib1dkY1RVVDhhLWZKUjdNQXZRbTdYWE5vWWttM3Y3TVFMMU5ZdER2TDJsOENBbmMwV2RTVElOVTZJUnZjNUtxbzJRNGNzTlg5U0hPbUVmem9ST2pRcWFoRWN2ZTFqQlhsdW9DWGRZdVlweDRfMXRmUmdHNmlpNFVoeGg2aUk4cU5NSlFYLWZMZnFoYmZZZnhCUVZSUHl3QmtBYklQNHgxRUFzYkM2RlNObWtoQ3hpTU5xRWd4YUlwWThDMmtKZEpfWklWLVdXNG5vRGR6cEtxSGN3bUI4RnNydW1sVllfRE5WdlVTRElpcGlxOVBiUDRIOTlUWE4xbzc0Nm9SYU5hMDdycTFob0NnTVNTeS04NVNhZ0NveGxteUUtRC1vZjlTc01ZOE9sOXQwcmR6cG9iQnVoeUpfbzVkZnZqS3cifX0.eyJodG0iOiJQT1NUIiwiaHR1IjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20vb2F1dGgyL3Rva2VuIiwiaWF0IjoxNzQ2ODA2MzA1LCJqdGkiOiI0YjIzNDBkMi1hOTFmLTQwYTUtYmFhOS1kZDRlNWRlYWM4NjcifQ.wq8gJ_G6vpiEinfaY3WhereqCCLoeJOG8tnWBBAzRWx9F1KU5yAAWq-ZVCk_k07-h6DIqz2wgv6y9dVbNpRYwNwDUeik9qLRsC60M8YW7EFVyI3n_NpujLwzZeub_nDYMVnyn4ii0NaZrYHtoGXOlswQfS_-ET-jpC0XWm5nBZsCdUEXjOYtwaACC6Js-pyNwKmSLp5SKIk11jZUR5xIIopaQy521y9qJHhGRwzj8DQGsP7wMZ98UFL0E--1c-hh4rTy8PMeWCqRHdwjj_ry_eTe0DJFcxxYQdeL7-0_0CIO4Ayx5WHEpcUOIzBRoN32RsNpDZc-5slDNj9ku004DA

grant_type=authorization_code\
&client_id=s6BhdRkqt\
&code=SplxlOBeZQQYbYS6WxSbIA\
&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb\
&code_verifier=bEaL42izcC-o-xBk0K2vuJ6U-y1p9r_wW2dFWIWgjz-

The following shows a representation of the DPoP Proof JWT header and claims:

{
  "typ": "dpop+jwt",
  "alg": "RS256",
  "jwk": {
    "kty": "RSA",
    "e": "AQAB",
    "n": "3FlqJr5TRskIQIgdE3Dd7D9lboWdcTUT8a-fJR7MAvQm7XXNoYkm3v7MQL1NYtDvL2l8CAnc0WdSTINU6IRvc5Kqo2Q4csNX9SHOmEfzoROjQqahEcve1jBXluoCXdYuYpx4_1tfRgG6ii4Uhxh6iI8qNMJQX-fLfqhbfYfxBQVRPywBkAbIP4x1EAsbC6FSNmkhCxiMNqEgxaIpY8C2kJdJ_ZIV-WW4noDdzpKqHcwmB8FsrumlVY_DNVvUSDIipiq9PbP4H99TXN1o746oRaNa07rq1hoCgMSSy-85SagCoxlmyE-D-of9SsMY8Ol9t0rdzpobBuhyJ_o5dfvjKw"
  }
}
{
  "htm": "POST",
  "htu": "https://server.example.com/oauth2/token",
  "iat": 1746806305,
  "jti": "4b2340d2-a91f-40a5-baa9-dd4e5deac867"
}

The following code shows an example of how to generate the DPoP Proof JWT:

RSAKey rsaKey = ...
JWKSource<SecurityContext> jwkSource = (jwkSelector, securityContext) -> jwkSelector
		.select(new JWKSet(rsaKey));
NimbusJwtEncoder jwtEncoder = new NimbusJwtEncoder(jwkSource);

JwsHeader jwsHeader = JwsHeader.with(SignatureAlgorithm.RS256)
		.type("dpop+jwt")
		.jwk(rsaKey.toPublicJWK().toJSONObject())
		.build();
JwtClaimsSet claims = JwtClaimsSet.builder()
		.issuedAt(Instant.now())
		.claim("htm", "POST")
		.claim("htu", "https://server.example.com/oauth2/token")
		.id(UUID.randomUUID().toString())
		.build();

Jwt dPoPProof = jwtEncoder.encode(JwtEncoderParameters.from(jwsHeader, claims));

After the authorization server successfully validates the DPoP proof, the public key from the DPoP proof will be bound (sender-constrained) to the issued access token.

The following access token response shows the token_type parameter as DPoP to signal to the client that the access token was bound to its DPoP proof public key:

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store

{
 "access_token": "Kz~8mXK1EalYznwH-LC-1fBAo.4Ljp~zsPE_NeO.gxU",
 "token_type": "DPoP",
 "expires_in": 2677
}

Public Key Confirmation

Resource servers MUST be able to identify whether an access token is DPoP-bound and verify the binding to the public key of the DPoP proof. The binding is accomplished by associating the public key with the access token in a way that can be accessed by the resource server, such as embedding the public key hash in the access token directly (JWT) or through token introspection.

When an access token is represented as a JWT, the public key hash is contained in the jkt claim under the confirmation method (cnf) claim.

The following example shows the claims of a JWT access token containing a cnf claim with a jkt claim, which is the JWK SHA-256 Thumbprint of the DPoP proof public key:

{
  "sub":"[email protected] (英語)  ",
  "iss":"https://server.example.com",
  "nbf":1562262611,
  "exp":1562266216,
  "cnf":
  {
    "jkt":"CQMknzRoZ5YUi7vS58jck1q8TmZT8wiIiXrCN1Ny4VU"
  }
}

OAuth2 トークンイントロスペクションエンドポイント

OAuth2TokenIntrospectionEndpointConfigurer は、OAuth2 トークンイントロスペクションエンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 イントロスペクションリクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2TokenIntrospectionEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.tokenIntrospectionEndpoint(tokenIntrospectionEndpoint ->
                    tokenIntrospectionEndpoint
                        .introspectionRequestConverter(introspectionRequestConverter)   (1)
                        .introspectionRequestConverters(introspectionRequestConvertersConsumer) (2)
                        .authenticationProvider(authenticationProvider) (3)
                        .authenticationProviders(authenticationProvidersConsumer)   (4)
                        .introspectionResponseHandler(introspectionResponseHandler) (5)
                        .errorResponseHandler(errorResponseHandler) (6)
				)
		);

	return http.build();
}
1introspectionRequestConverter()HttpServletRequest から OAuth2 イントロスペクションリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2TokenIntrospectionAuthenticationToken のインスタンスに追加します。
2introspectionRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2TokenIntrospectionAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5introspectionResponseHandler(): 「認証された」 OAuth2TokenIntrospectionAuthenticationToken を処理し、OAuth2TokenIntrospection レスポンス [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。

OAuth2TokenIntrospectionEndpointConfigurer は OAuth2TokenIntrospectionEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OAuth2TokenIntrospectionEndpointFilter は、OAuth2 イントロスペクションリクエストを処理する Filter です。

OAuth2TokenIntrospectionEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2TokenIntrospectionAuthenticationConverter

  • AuthenticationManager —  OAuth2TokenIntrospectionAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler — 「認証済み」 OAuth2TokenIntrospectionAuthenticationToken を処理し、OAuth2TokenIntrospection レスポンスを返す内部実装。

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

OAuth2 トークン失効エンドポイント

OAuth2TokenRevocationEndpointConfigurer は、OAuth2 トークン失効エンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 取り消しリクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2TokenRevocationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.tokenRevocationEndpoint(tokenRevocationEndpoint ->
                    tokenRevocationEndpoint
                        .revocationRequestConverter(revocationRequestConverter) (1)
                        .revocationRequestConverters(revocationRequestConvertersConsumer)   (2)
                        .authenticationProvider(authenticationProvider) (3)
                        .authenticationProviders(authenticationProvidersConsumer)   (4)
                        .revocationResponseHandler(revocationResponseHandler)   (5)
                        .errorResponseHandler(errorResponseHandler) (6)
				)
		);

	return http.build();
}
1revocationRequestConverter()HttpServletRequest から OAuth2 取り消しリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2TokenRevocationAuthenticationToken のインスタンスに追加します。
2revocationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2TokenRevocationAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5revocationResponseHandler(): 「認証された」 OAuth2TokenRevocationAuthenticationToken を処理し、OAuth2 取り消しレスポンス [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。

OAuth2TokenRevocationEndpointConfigurer は OAuth2TokenRevocationEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OAuth2TokenRevocationEndpointFilter は、OAuth2 取り消しリクエストを処理する Filter です。

OAuth2TokenRevocationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2TokenRevocationAuthenticationConverter

  • AuthenticationManager —  OAuth2TokenRevocationAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler — 「認証済み」 OAuth2TokenRevocationAuthenticationToken を処理し、OAuth2 失効レスポンスを返す内部実装。

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

OAuth2 認証サーバーメタデータエンドポイント

OAuth2AuthorizationServerMetadataEndpointConfigurer は、OAuth2 認証サーバーメタデータエンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 認可サーバーメタデータレスポンス [IETF] (英語) をカスタマイズできる拡張ポイントを定義します。

OAuth2AuthorizationServerMetadataEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
				.authorizationServerMetadataEndpoint(authorizationServerMetadataEndpoint ->
                    authorizationServerMetadataEndpoint
                        .authorizationServerMetadataCustomizer(authorizationServerMetadataCustomizer)   (1)
				)
		);

	return http.build();
}
1authorizationServerMetadataCustomizer()OAuth2AuthorizationServerMetadata.Builder へのアクセスを提供する Consumer は、認可サーバーの構成のクレームをカスタマイズする機能を認可します。

OAuth2AuthorizationServerMetadataEndpointConfigurer は OAuth2AuthorizationServerMetadataEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OAuth2AuthorizationServerMetadataEndpointFilter は、OAuth2AuthorizationServerMetadata レスポンス [IETF] (英語) を返す Filter です。

JWK セットエンドポイント

OAuth2AuthorizationServerConfigurer は JWK セットエンドポイント [IETF] (英語) のサポートを提供します。

OAuth2AuthorizationServerConfigurer は NimbusJwkSetEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。NimbusJwkSetEndpointFilter は、JWK セット [IETF] (英語) を返す Filter です。

JWK Set エンドポイントは、JWKSource<SecurityContext> @Bean が登録されている場合にのみ構成されます。

OpenID Connect 1.0 プロバイダー構成エンドポイント

OidcProviderConfigurationEndpointConfigurer は、OpenID Connect 1.0 プロバイダー構成エンドポイント (英語) をカスタマイズする機能を提供します。OpenID プロバイダー構成のレスポンス (英語) をカスタマイズできる拡張ポイントを定義します。

OidcProviderConfigurationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
                .oidc(oidc ->
                    oidc
                        .providerConfigurationEndpoint(providerConfigurationEndpoint ->
                            providerConfigurationEndpoint
                                .providerConfigurationCustomizer(providerConfigurationCustomizer)   (1)
                        )
                )
		);

	return http.build();
}
1providerConfigurationCustomizer()OidcProviderConfiguration.Builder へのアクセスを提供する Consumer により、OpenID プロバイダーの構成のクレームをカスタマイズできます。

OidcProviderConfigurationEndpointConfigurer は OidcProviderConfigurationEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OidcProviderConfigurationEndpointFilter は、OidcProviderConfiguration レスポンス (英語) を返す Filter です。

OpenID Connect 1.0 ログアウトエンドポイント

OidcLogoutEndpointConfigurer は、OpenID Connect 1.0 ログアウトエンドポイント (英語) をカスタマイズする機能を提供します。これは、RP によって開始されたログアウトリクエストの前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OidcLogoutEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
                .oidc(oidc ->
                    oidc
                        .logoutEndpoint(logoutEndpoint ->
                            logoutEndpoint
                                .logoutRequestConverter(logoutRequestConverter) (1)
                                .logoutRequestConverters(logoutRequestConvertersConsumer)   (2)
                                .authenticationProvider(authenticationProvider) (3)
                                .authenticationProviders(authenticationProvidersConsumer)   (4)
                                .logoutResponseHandler(logoutResponseHandler)   (5)
                                .errorResponseHandler(errorResponseHandler) (6)
                        )
                )
		);

	return http.build();
}
1logoutRequestConverter()HttpServletRequest からログアウトリクエスト (英語) を OidcLogoutAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。
2logoutRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OidcLogoutAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5logoutResponseHandler()AuthenticationSuccessHandler ( ポストプロセッサー ) は、「認証された」 OidcLogoutAuthenticationToken を処理し、ログアウトを実行するために使用されます。
6errorResponseHandler()AuthenticationFailureHandler ( ポストプロセッサー ) は、OAuth2AuthenticationException を処理し、エラーレスポンスを返すために使用されます。

OidcLogoutEndpointConfigurer は OidcLogoutEndpointFilter を構成し、OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OidcLogoutEndpointFilter は、RP によって開始されたログアウトリクエスト (英語) を処理し、エンドユーザーのログアウトを実行する Filter です。

OidcLogoutEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OidcLogoutAuthenticationConverter

  • AuthenticationManager —  OidcLogoutAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler —  OidcLogoutAuthenticationSuccessHandler

  • AuthenticationFailureHandler —  OAuth2AuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

OidcLogoutAuthenticationProvider は、SessionRegistry を使用して、ログアウトをリクエストしているエンドユーザーに関連付けられた SessionInformation インスタンスを検索します。
OidcClientInitiatedLogoutSuccessHandler は、OpenID Connect 1.0 RP によって開始されるログアウトを構成するための Spring Security の OAuth2 クライアントサポートの対応する構成です。

ログアウトリクエストの検証のカスタマイズ

OidcLogoutAuthenticationValidator は、特定の OpenID Connect RP 開始ログアウトリクエストパラメーターを検証するために使用されるデフォルトのバリデータです。デフォルトの実装では、post_logout_redirect_uri パラメーターが検証されます。検証が失敗すると、OAuth2AuthenticationException がスローされます。

OidcLogoutAuthenticationProvider は、型 Consumer<OidcLogoutAuthenticationContext> のカスタム認証検証を setAuthenticationValidator() に提供することにより、デフォルトのログアウトリクエスト検証をオーバーライドする機能を提供します。

OidcLogoutAuthenticationContext は、ログアウトリクエストパラメーターを含む OidcLogoutAuthenticationToken を保持します。
検証が失敗した場合、認証バリデータ MUST は OAuth2AuthenticationException をスローします。

次の例は、カスタム認証バリデータを使用して OidcLogoutAuthenticationProvider を構成する方法を示しています。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
                .oidc(oidc ->
                    oidc
                        .logoutEndpoint(logoutEndpoint ->
                            logoutEndpoint
                                .authenticationProviders(configureAuthenticationValidator())
                        )
                )
		);

	return http.build();
}

private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
	return (authenticationProviders) ->
			authenticationProviders.forEach((authenticationProvider) -> {
				if (authenticationProvider instanceof OidcLogoutAuthenticationProvider oidcLogoutAuthenticationProvider) {
					Consumer<OidcLogoutAuthenticationContext> authenticationValidator = new CustomPostLogoutRedirectUriValidator();
					oidcLogoutAuthenticationProvider.setAuthenticationValidator(authenticationValidator);
				}
			});
}

static class CustomPostLogoutRedirectUriValidator implements Consumer<OidcLogoutAuthenticationContext> {

	@Override
	public void accept(OidcLogoutAuthenticationContext authenticationContext) {
		OidcLogoutAuthenticationToken oidcLogoutAuthentication =
				authenticationContext.getAuthentication();
		RegisteredClient registeredClient = authenticationContext.getRegisteredClient();

		// TODO

	}
}

OpenID Connect 1.0 UserInfo エンドポイント

OidcUserInfoEndpointConfigurer は、OpenID Connect 1.0 UserInfo エンドポイント (英語) をカスタマイズする機能を提供します。UserInfo リクエスト (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OidcUserInfoEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
                .oidc(oidc ->
                    oidc
                        .userInfoEndpoint(userInfoEndpoint ->
                            userInfoEndpoint
                                .userInfoRequestConverter(userInfoRequestConverter) (1)
                                .userInfoRequestConverters(userInfoRequestConvertersConsumer)   (2)
                                .authenticationProvider(authenticationProvider) (3)
                                .authenticationProviders(authenticationProvidersConsumer)   (4)
                                .userInfoResponseHandler(userInfoResponseHandler)   (5)
                                .errorResponseHandler(errorResponseHandler) (6)
                                .userInfoMapper(userInfoMapper) (7)
                        )
                )
		);

	return http.build();
}
1userInfoRequestConverter()HttpServletRequest から UserInfo リクエスト (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OidcUserInfoAuthenticationToken のインスタンスに追加します。
2userInfoRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OidcUserInfoAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5userInfoResponseHandler(): 「認証された」 OidcUserInfoAuthenticationToken を処理し、UserInfo レスポンス (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して UserInfo エラーレスポンス (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。
7userInfoMapper()OidcUserInfoAuthenticationContext から OidcUserInfo のインスタンスへのクレームを抽出するために使用される Function

OidcUserInfoEndpointConfigurer は OidcUserInfoEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OidcUserInfoEndpointFilter は、UserInfo リクエスト (英語) を処理して OidcUserInfo レスポンス (英語) を返す Filter です。

OidcUserInfoEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  SecurityContext から Authentication を取得し、プリンシパルで OidcUserInfoAuthenticationToken を作成する内部実装。

  • AuthenticationManager —  OidcUserInfoAuthenticationProvider で構成される AuthenticationManager。認可時にリクエストされたスコープ (英語) に基づいて ID トークン (英語) から標準クレーム (英語) を抽出する userInfoMapper の内部実装に関連付けられています。

  • AuthenticationSuccessHandler — 「認証済み」 OidcUserInfoAuthenticationToken を処理し、OidcUserInfo レスポンスを返す内部実装。

  • AuthenticationFailureHandler —  OAuth2AuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

OAuth2TokenCustomizer<JwtEncodingContext> @Bean を提供することで、ID トークンをカスタマイズできます。

OpenID Connect 1.0 UserInfo エンドポイントは OAuth2 で保護されたリソースであり、UserInfo リクエスト (英語) でベアラートークンとして送信されるアクセストークンを REQUIRES します。

OAuth2 リソースサーバーのサポートは自動構成されますが、OpenID Connect 1.0 UserInfo エンドポイントの場合、JwtDecoder @Bean は REQUIRED になります。
ガイド使い方: OpenID Connect 1.0 UserInfo レスポンスをカスタマイズするには、UserInfo エンドポイントをカスタマイズする例が含まれています。

OpenID Connect 1.0 クライアント登録エンドポイント

OidcClientRegistrationEndpointConfigurer は、OpenID Connect 1.0 クライアント登録エンドポイント (英語) をカスタマイズする機能を提供します。クライアント登録リクエスト (英語) またはクライアント読み取りリクエスト (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OidcClientRegistrationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
			OAuth2AuthorizationServerConfigurer.authorizationServer();

	http
		.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
		.with(authorizationServerConfigurer, (authorizationServer) ->
			authorizationServer
                .oidc(oidc ->
                    oidc
                        .clientRegistrationEndpoint(clientRegistrationEndpoint ->
                            clientRegistrationEndpoint
                                .clientRegistrationRequestConverter(clientRegistrationRequestConverter) (1)
                                .clientRegistrationRequestConverters(clientRegistrationRequestConvertersConsumers)  (2)
                                .authenticationProvider(authenticationProvider) (3)
                                .authenticationProviders(authenticationProvidersConsumer)   (4)
                                .clientRegistrationResponseHandler(clientRegistrationResponseHandler)   (5)
                                .errorResponseHandler(errorResponseHandler) (6)
                        )
                )
		);

	return http.build();
}
1clientRegistrationRequestConverter()HttpServletRequest からクライアント登録リクエスト (英語) またはクライアント読み取りリクエスト (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OidcClientRegistrationAuthenticationToken のインスタンスに追加します。
2clientRegistrationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OidcClientRegistrationAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5clientRegistrationResponseHandler(): 「認証された」 OidcClientRegistrationAuthenticationToken を処理し、クライアント登録レスポンス (英語) またはクライアント読み取りレスポンス (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理し、クライアント登録エラーレスポンス (英語) またはクライアント読み取りエラーレスポンス (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。
多くの デプロイは動的クライアント登録を必要としないため、OpenID Connect 1.0 クライアント登録エンドポイントはデフォルトで無効になっています。

OidcClientRegistrationEndpointConfigurer は OidcClientRegistrationEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OidcClientRegistrationEndpointFilter は、クライアント登録リクエスト (英語) を処理して OidcClientRegistration レスポンス (英語) を返す Filter です。

OidcClientRegistrationEndpointFilter もクライアント読み取りリクエスト (英語) を処理し、OidcClientRegistration レスポンス (英語) を返します。

OidcClientRegistrationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OidcClientRegistrationAuthenticationConverter

  • AuthenticationManager —  OidcClientRegistrationAuthenticationProvider と OidcClientConfigurationAuthenticationProvider で構成される AuthenticationManager

  • AuthenticationSuccessHandler — 「認証済み」 OidcClientRegistrationAuthenticationToken を処理し、OidcClientRegistration レスポンスを返す内部実装。

  • AuthenticationFailureHandler —  OAuth2AuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

OpenID Connect 1.0 クライアント登録エンドポイントは OAuth2 で保護されたリソース (英語) であり、REQUIRES はクライアント登録 (またはクライアント読み取り) リクエストでベアラートークンとして送信されるアクセストークンです。

OAuth2 リソースサーバーのサポートは自動構成されますが、OpenID Connect 1.0 クライアント登録エンドポイントでは JwtDecoder @Bean は REQUIRED になります。
クライアント登録リクエスト REQUIRES のアクセストークン、OAuth2 スコープ client.create
クライアント読み取りリクエスト REQUIRES のアクセストークン、OAuth2 スコープ client.read