{"id":28062,"date":"2025-04-19T22:41:09","date_gmt":"2025-04-19T14:41:09","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/28062.html"},"modified":"2025-04-19T22:41:09","modified_gmt":"2025-04-19T14:41:09","slug":"%e5%9f%ba%e4%ba%8espring-security-6%e7%9a%84oauth2-%e7%b3%bb%e5%88%97%e4%b9%8b%e5%85%ab-%e6%8e%88%e6%9d%83%e6%9c%8d%e5%8a%a1%e5%99%a8-spring-authrization-server%e7%9a%84%e5%9f%ba%e6%9c%ac%e5%8e%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/28062.html","title":{"rendered":"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668--Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406"},"content":{"rendered":"<p>\u4e4b\u6240\u4ee5\u60f3\u5199\u8fd9\u4e00\u7cfb\u5217&#xff0c;\u662f\u56e0\u4e3a\u4e4b\u524d\u5de5\u4f5c\u8fc7\u7a0b\u4e2d\u4f7f\u7528Spring Security OAuth2\u642d\u5efa\u4e86\u7f51\u5173\u548c\u6388\u6743\u670d\u52a1\u5668&#xff0c;\u4f46\u5f53\u65f6\u57fa\u4e8espring-boot 2.3.x&#xff0c;\u5176\u9ed8\u8ba4\u7684Spring Security\u662f5.3.x\u3002\u4e4b\u540e\u65b0\u9879\u76ee\u5347\u7ea7\u5230\u4e86spring-boot 3.3.0&#xff0c;\u7ed3\u679c\u4e00\u770bSpring Security\u4e5f\u5347\u7ea7\u4e3a6.3.0\u3002\u65e0\u8bba\u662fSpring Security\u7684\u98ce\u683c\u548c\u4ee5\u53caOAuth2\u90fd\u505a\u4e86\u8f83\u5927\u6539\u52a8&#xff0c;\u91cc\u9762\u751a\u81f3\u5c06\u6388\u6743\u670d\u52a1\u5668\u6a21\u5757\u90fd\u79fb\u9664\u4e86&#xff0c;\u5bfc\u81f4\u5728\u914d\u7f6e\u540c\u6837\u529f\u80fd\u65f6&#xff0c;\u82b1\u8d39\u4e86\u4e9b\u65f6\u95f4\u7814\u7a76\u65b0\u7248\u672c\u7684\u5e95\u5c42\u539f\u7406&#xff0c;\u8fd9\u91cc\u5c06\u4e00\u4e9b\u5b66\u4e60\u7ecf\u9a8c\u5206\u4eab\u7ed9\u5927\u5bb6\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u7531\u4e8e\u6846\u67b6\u4e0d\u540c\u7248\u672c\u6539\u9020\u4f1a\u6709\u4e9b\u4f7f\u7528\u7684\u4e0d\u540c&#xff0c;\u56e0\u6b64\u672c\u6b21\u7cfb\u5217\u4e2d\u4f7f\u7528\u57fa\u672c\u6846\u67b6\u662f spring-boo-3.3.0&#xff08;\u9ed8\u8ba4\u5f15\u5165\u7684Spring Security\u662f6.3.0&#xff09;&#xff0c;JDK\u7248\u672c\u4f7f\u7528\u7684\u662f19&#xff0c;\u672c\u7cfb\u5217OAuth2\u7684\u4ee3\u7801\u91c7\u7528Spring Security6.3.0\u6846\u67b6&#xff0c;\u6240\u6709\u4ee3\u7801\u90fd\u5728oauth2-study\u9879\u76ee\u4e0a&#xff1a;https:\/\/github.com\/forever1986\/oauth2-study.git<\/p>\n<\/p>\n<h4>\u76ee\u5f55<\/h4>\n<ul>\n<li>1 \u5173\u952e\u7684\u7c7b<\/li>\n<li>\n<ul>\n<li>1.1 Authentication<\/li>\n<li>1.2 AuthenticationConverter<\/li>\n<li>1.3 AuthenticationProvider<\/li>\n<\/ul>\n<\/li>\n<li>2 \u6388\u6743\u7801\u6a21\u5f0f\u7684\u5e95\u5c42\u539f\u7406<\/li>\n<li>3 \u6388\u6743\u7801\u6a21\u5f0f\u6574\u4f53\u6d41\u7a0b\u56fe<\/li>\n<li>4 \u5173\u952e\u7684Filter\u8fc7\u6ee4\u5668<\/li>\n<li>\n<ul>\n<li>4.1 OAuth2AuthorizationEndpointFilter&#xff08;\u6388\u6743\u7801code\u8bf7\u6c42\u5904\u7406&#xff09;<\/li>\n<li>4.2 OAuth2TokenEndpointFilter&#xff08;\u8fd4\u56detoken&#xff09;<\/li>\n<li>4.3 OAuth2ClientAuthenticationFilter&#xff08;\u5ba2\u6237\u7aef\u8ba4\u8bc1&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u524d\u9762\u6211\u4eec\u4e86\u89e3\u6388\u6743\u670d\u52a1\u5668\u7684\u5b9e\u73b0\u4ee5\u53ca\u81ea\u5b9a\u4e49\u5ba2\u6237\u7aef\u3001\u81ea\u5b9a\u4e49\u6388\u6743\u9875\u9762&#xff0c;\u4e5f\u7aa5\u63a2\u4e86\u5176\u4e2d\u90e8\u5206\u539f\u7406\u3002\u8fd9\u4e00\u7ae0&#xff0c;\u6211\u4eec\u901a\u8fc7\u6388\u6743\u7801\u6a21\u5f0f\u4e0b&#xff0c;\u5206\u6790\u4e00\u4e0bSpring Authrization Server\u7684\u57fa\u672c\u539f\u7406&#xff0c;\u540c\u65f6\u5bf9\u5176\u4e2d\u4e00\u4e9b\u5173\u952e\u7684Filter\u8fc7\u6ee4\u5668\u5217\u51fa\u6765&#xff0c;\u5bf9\u540e\u7eed\u5b9e\u73b0\u529f\u80fd\u4f1a\u6709\u5e2e\u52a9\u3002\u6211\u4eec\u77e5\u9053Spring Authrization Server\u4e5f\u662f\u57fa\u4e8eSpring Security 6\u57fa\u7840\u4e0a\u5b9e\u73b0\u7684&#xff0c;\u56e0\u6b64\u5176\u5173\u952e\u529f\u80fd\u90fd\u5728\u5176\u8fc7\u6ee4\u5668\u4e0a\u9762\u3002\u4e0b\u56fe\u7ea2\u8272\u6846\u6846\u7684\u662fSpring Authrization Server\u65b0\u589e\u7684\u8fc7\u6ee4\u5668&#xff0c;\u6211\u4eec\u6311\u4e00\u4e9b\u5173\u952e\u7684\u89e3\u91ca\u4e00\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144105-6803b60162fdc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>1 \u5173\u952e\u7684\u7c7b<\/h2>\n<p>\u5728\u4ecb\u7ecd\u5173\u952e\u7684\u8fc7\u6ee4\u5668\u4e4b\u524d&#xff0c;\u6709\u51e0\u4e2a\u7c7b\u9700\u8981\u5148\u8bf4\u660e\u4e00\u4e0b\u5176\u4f5c\u7528&#xff0c;\u5bf9\u540e\u9762\u9605\u8bfb\u6e90\u7801\u6709\u5f88\u597d\u7684\u7406\u89e3\u3002<\/p>\n<h3>1.1 Authentication<\/h3>\n<p>Authentication\u5176\u5b9e\u662fSpring Security\u7684\u63a5\u53e3&#xff0c;\u4e3b\u8981\u5c31\u662f\u5c01\u88c5\u8ba4\u8bc1\u4fe1\u606f&#xff0c;\u7528\u4e8e\u4e0a\u4e0b\u6587\u4f20\u8f93&#xff0c;\u800c\u5728Spring Authrization Server\u4e2d&#xff0c;\u6709\u51e0\u4e2a\u5b9e\u73b0\u7c7b\u6bd4\u8f83\u91cd\u8981&#xff1a;<\/p>\n<ul>\n<li>OAuth2AuthorizationCodeRequestAuthenticationToken&#xff1a;\u5728\u6388\u6743\u7801\u6a21\u5f0f\u4e0b&#xff0c;\u83b7\u53d6\u6388\u6743\u7801\u65f6\u5019\u5c01\u88c5\u7684\u4fe1\u606f<\/li>\n<li>OAuth2AuthorizationConsentAuthenticationToken&#xff1a;\u5728\u6388\u6743\u7801\u6a21\u5f0f\u4e0b&#xff0c;\u8df3\u8f6c\u6388\u6743\u754c\u9762\u65f6&#xff0c;\u5c01\u88c5\u6240\u9700\u7684\u4fe1\u606f<\/li>\n<li>OAuth2AuthorizationCodeAuthenticationToken&#xff1a;\u5728\u8bf7\u6c42token\u65f6&#xff0c;\u5c01\u88c5\u6240\u9700\u7684\u4fe1\u606f<\/li>\n<li>OAuth2TokenExchangeAuthenticationToken&#xff1a;\u5728\u4ea4\u6362token\u8bf7\u6c42\u4e0b&#xff0c;\u5c01\u88c5\u6240\u9700\u7684\u4fe1\u606f<\/li>\n<li>OAuth2RefreshTokenAuthenticationToken&#xff1a;\u5728\u5237\u65b0token\u8bf7\u6c42\u4e0b&#xff0c;\u5c01\u88c5\u6240\u9700\u7684\u4fe1\u606f<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144105-6803b6018fb2e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>1.2 AuthenticationConverter<\/h3>\n<p>AuthenticationConverter\u662f\u4e00\u4e2arequest\u53c2\u6570\u8f6c\u6362\u4e3aAuthentication\u7684\u4e00\u4e2a\u8f6c\u6362\u5668&#xff0c;\u5176\u4e2d\u6709\u51e0\u4e2a\u5b9e\u73b0\u7c7b\u6bd4\u8f83\u91cd\u8981<\/p>\n<ul>\n<li>OAuth2AuthorizationCodeRequestAuthenticationConverter&#xff1a;\u5728\u8bf7\u6c42\u6388\u6743\u7801\u65f6&#xff0c;\u5c06request\u7684\u53c2\u6570\u90fd\u5c01\u88c5\u4e3aAuthentication<\/li>\n<li>OAuth2AuthorizationConsentAuthenticationConverter&#xff1a;\u5728\u8bf7\u6c42\u6388\u6743\u7801\u65f6&#xff0c;\u70b9\u51fb\u6388\u6743\u9875\u9762\u7684\u786e\u8ba4\u540e&#xff0c;\u5c06request\u7684\u53c2\u6570\u90fd\u5c01\u88c5\u4e3aAuthentication<\/li>\n<li>OAuth2AuthorizationCodeAuthenticationConverter&#xff1a;\u5728\u8bf7\u6c42token\u65f6&#xff0c;\u5c06request\u7684\u53c2\u6570\u90fd\u5c01\u88c5\u4e3aAuthentication<\/li>\n<li>OAuth2TokenExchangeAuthenticationConverter&#xff1a;\u5728\u4ea4\u6362token\u65f6&#xff0c;\u5c06request\u7684\u53c2\u6570\u90fd\u5c01\u88c5\u4e3aAuthentication<\/li>\n<li>OAuth2RefreshTokenAuthenticationConverter&#xff1a;\u5728\u5237\u65b0token\u65f6&#xff0c;\u5c06request\u7684\u53c2\u6570\u90fd\u5c01\u88c5\u4e3aAuthentication<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144105-6803b601d7ba9.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>1.3 AuthenticationProvider<\/h3>\n<p>AuthenticationProvider\u672c\u8eab\u662fSpring Security\u7684\u63a5\u53e3&#xff0c;\u4e3b\u8981\u662f\u7528\u4e8e\u9a8c\u8bc1\u7ed3\u679c&#xff0c;\u6bd4\u5982\u7528\u6237\u540d\u5bc6\u7801\u767b\u5f55\u7b49&#xff0c;\u8fd9\u91ccSpring Authrization Server\u901a\u8fc7\u5b9e\u73b0\u4e0d\u540c\u7684AuthenticationProvider\u505a\u4e0d\u540c\u9a8c\u8bc1&#xff0c;\u4ee5\u4e0b\u51e0\u4e2a\u5b9e\u73b0\u7c7b\u6bd4\u8f83\u91cd\u8981&#xff1a;<\/p>\n<ul>\n<li>OAuth2AuthorizationCodeRequestAuthenticationProvider&#xff1a;\u4e3b\u8981\u7528\u4e8e\u6388\u6743\u7801\u6a21\u5f0f\u4e0b&#xff0c;\u5ba2\u6237\u7aef\u7684\u9a8c\u8bc1<\/li>\n<li>OAuth2AuthorizationConsentAuthenticationProvider&#xff1a;\u6388\u6743\u9875\u9762\u70b9\u51fb\u786e\u8ba4\u4e4b\u540e&#xff0c;\u5ba2\u6237\u7aef\u9a8c\u8bc1<\/li>\n<li>OAuth2AuthorizationCodeAuthenticationProvider&#xff1a;\u83b7\u53d6token\u63a5\u53e3\u65f6&#xff0c;\u5ba2\u6237\u7aef\u9a8c\u8bc1<\/li>\n<li>OAuth2TokenExchangeAuthenticationProvider&#xff1a;\u4ea4\u6362token\u63a5\u53e3\u65f6&#xff0c;\u5ba2\u6237\u7aef\u9a8c\u8bc1<\/li>\n<li>OAuth2RefreshTokenAuthenticationProvider&#xff1a;\u8bf7\u6c42\u5237\u65b0token\u63a5\u53e3\u65f6&#xff0c;\u5ba2\u6237\u7aef\u9a8c\u8bc1<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144106-6803b6021f069.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>2 \u6388\u6743\u7801\u6a21\u5f0f\u7684\u5e95\u5c42\u539f\u7406<\/h2>\n<p>1&#xff09;\u6211\u4eec\u4ece\u300a\u7cfb\u5217\u4e4b\u56db-\u5ba2\u6237\u7aef\u2013oauth2-client\u5e95\u5c42\u539f\u7406\u300b\u4e2d\u53ef\u77e5&#xff0c;\u5ba2\u6237\u7aef\u4f1a\u8bbf\u95ee\/oauth2\/authorize\u63a5\u53e3&#xff0c;\u8fd9\u65f6\u5019\u4f1a\u6709\u5148\u5230\u8fbeOAuth2AuthorizationEndpointFilter\u8fc7\u6ee4\u5668&#xff0c;\u4f46\u662f\u7531\u4e8e\u672a\u767b\u5f55&#xff0c;\u56e0\u6b64\u4f1a\u88ab\u8ba4\u5b9a\u6ca1\u6709\u6743\u9650&#xff0c;\u4e0d\u505a\u5904\u7406&#xff0c;\u7ee7\u7eed\u8d70\u8fc7\u6ee4\u5668\u94fe\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144106-6803b6025e2dc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144106-6803b60287412.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>2&#xff09;\u63a5\u7740&#xff0c;\u8bf7\u6c42\u4f1a\u63a5\u7740\u8df3\u8f6c\u5230AuthorizationFilter\u8fc7\u6ee4\u5668&#xff08;\u8fd9\u662fSpring Security\u7684\u8fc7\u6ee4\u5668&#xff0c;\u505a\u8ba4\u8bc1\u5224\u65ad\u7684&#xff09;&#xff0c;\u8fd9\u65f6\u5019\u4f1a\u62a5AccessDeniedException\u5f02\u5e38&#xff0c;\u5e76\u7531LoginUrlAuthenticationEntryPoint\u5904\u7406&#xff0c;\u8df3\u8f6c\u5230Spring Security\u7684\u767b\u5f55\u754c\u9762<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144106-6803b602bbcfb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>3&#xff09;\u51fa\u73b0\u767b\u5f55\u754c\u9762&#xff0c;\u8fdb\u884c\u767b\u5f55\u4e4b\u540e&#xff0c;\u4f1a\u7ee7\u7eed\u8bf7\u6c42\/oauth2\/authorize\u63a5\u53e3&#xff0c;\u8fd9\u65f6\u5019\u4f1a\u88abOAuth2AuthorizationEndpointFilter\u62e6\u622a&#xff0c;\u6211\u4eec\u518d\u770b\u770bOAuth2AuthorizationEndpointFilter\u7684doFilterInternal\u65b9\u6cd5<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144106-6803b602ed34d.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\u7b2c\u4e00\u6b65&#xff1a;\u5224\u65adURI\u662f\u5426\u7b26\u5408\/oauth2\/authorize<\/li>\n<li>\u7b2c\u4e8c\u6b65&#xff1a;\u5224\u65ad\u5ba2\u6237\u7aef\u4fe1\u606f\u662f\u5426\u7b26\u5408\u8981\u6c42<\/li>\n<li>\u7b2c\u4e09\u6b65&#xff1a;\u5224\u65ad\u662f\u5426\u5df2\u7ecf\u767b\u5f55&#xff0c;\u6ca1\u6709\u767b\u5f55&#xff0c;\u5219\u7531\u5176\u5b83\u8fc7\u6ee4\u5668\u8df3\u8f6c\u5230\u767b\u5f55\u754c\u9762<\/li>\n<li>\u7b2c\u56db\u6b65&#xff1a;\u5224\u65ad\u662f\u5426\u5df2\u7ecf\u6388\u6743&#xff0c;\u6ca1\u6709\u6388\u6743\u5219\u8df3\u8f6c\u5230\u767b\u5f55\u754c\u9762<\/li>\n<li>\u7b2c\u4e94\u6b65&#xff1a;\u524d\u97624\u6b65\u90fd\u6ca1\u95ee\u9898&#xff0c;\u5219\u8fd4\u56de\u6388\u6743\u7684code<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u7684\u6e90\u7801\u8c03\u7528\u8fc7\u7a0b\u5217\u51fa\u6765&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144107-6803b6036dd05.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>4&#xff09;\u8fd4\u56de\u6388\u6743\u7801\u7ed9\u5ba2\u6237\u7684\u4e4b\u540e&#xff0c;\u5ba2\u6237\u7aef\u4f1a\u7ee7\u7eed\u8bf7\u6c42http:\/\/oauth-server:9000\/oauth2\/token\u83b7\u53d6token&#xff0c;\u800c\u6388\u6743\u670d\u52a1\u5668\u7684token\u7531OAuth2TokenEndpointFilter\u8fc7\u6ee4\u5668\u5904\u7406<\/p>\n<p>OAuth2TokenEndpointFilter\u662f\u62e6\u622a&#034;\/oauth2\/token&#034;\u83b7\u53d6token\u8bf7\u6c42&#xff0c;\u901a\u8fc7\u5c06request\u7684\u53c2\u6570\u5c01\u88c5\u4e3aOAuth2AuthorizationCodeAuthenticationToken&#xff0c;\u7136\u540e\u8c03\u7528OAuth2AuthorizationCodeAuthenticationProvider\u9a8c\u8bc1\u5e76\u751f\u6210token&#xff0c;\u901a\u8fc7\u540e\u8c03\u7528OAuth2AccessTokenResponseAuthenticationSuccessHandler\u8fd4\u56detoken<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144108-6803b60407125.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>3 \u6388\u6743\u7801\u6a21\u5f0f\u6574\u4f53\u6d41\u7a0b\u56fe<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144108-6803b60474e2c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>4 \u5173\u952e\u7684Filter\u8fc7\u6ee4\u5668<\/h2>\n<p>\u4ece\u4e0a\u9762\u7684\u6574\u4f53\u6d41\u7a0b&#xff0c;\u6211\u4eec\u77e5\u9053\u4e00\u4e9b\u5173\u952e\u7684Filter\u8fc7\u6ee4\u5668&#xff0c;\u8fd9\u91cc\u7f57\u5217\u51fa\u6765&#xff0c;\u540e\u7eed\u8bb2\u89e3\u6388\u6743\u7801\u5176\u5b83\u529f\u80fd\u65f6&#xff0c;\u4f1a\u7ecf\u5e38\u63d0\u5230\u3002<\/p>\n<h3>4.1 OAuth2AuthorizationEndpointFilter&#xff08;\u6388\u6743\u7801code\u8bf7\u6c42\u5904\u7406&#xff09;<\/h3>\n<p>\u5728\u300a\u7cfb\u5217\u4e4b\u4e94 &#8211; \u6388\u6743\u670d\u52a1\u5668\u2013\u5f00\u7bc7\u300b\u548c\u672c\u7cfb\u5217\u4e2d\u5206\u6790\u8fc7\u8be5\u8fc7\u6ee4\u5668\u3002\u8be5\u8fc7\u6ee4\u5668\u4e13\u95e8\u5904\u7406\/oauth2\/authorize\u63a5\u53e3&#xff0c;\u5728\u6388\u6743\u7801\u6a21\u5f0f\u4e0b&#xff0c;\u8be5\u63a5\u53e3\u5c31\u662f\u7528\u4e8e\u8df3\u8f6c\u5230\u6388\u6743\u754c\u9762\u4ee5\u53ca\u8fd4\u56de\u6388\u6743\u7801\u7684\u4f5c\u7528<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144106-6803b6025e2dc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>4.2 OAuth2TokenEndpointFilter&#xff08;\u8fd4\u56detoken&#xff09;<\/h3>\n<p>OAuth2TokenEndpointFilter\u662f\u62e6\u622a&#034;\/oauth2\/token&#034;\u83b7\u53d6token\u8bf7\u6c42&#xff0c;\u901a\u8fc7\u5c06request\u7684\u53c2\u6570\u5c01\u88c5\u4e3aOAuth2AuthorizationCodeAuthenticationToken&#xff0c;\u7136\u540e\u8c03\u7528OAuth2AuthorizationCodeAuthenticationProvider\u9a8c\u8bc1\u5e76\u751f\u6210token&#xff0c;\u901a\u8fc7\u540e\u8c03\u7528OAuth2AccessTokenResponseAuthenticationSuccessHandler\u8fd4\u56detoken<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144108-6803b60407125.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>4.3 OAuth2ClientAuthenticationFilter&#xff08;\u5ba2\u6237\u7aef\u8ba4\u8bc1&#xff09;<\/h3>\n<p>OAuth2ClientAuthenticationFilter\u4e3b\u8981\u662f\u7528\u4e8e\u5ba2\u6237\u7aef\u8ba4\u8bc1&#xff0c;\u5305\u62ec\u901a\u8fc7client_secret_basic\u3001client_secret_post\u3001client_secret_jwt\u3001private_key_jwt\u3001none\u3001tls_client_auth\u548cself_signed_tls_client_auth\u7b49\u4e0d\u540c\u8ba4\u8bc1\u65b9\u5f0f\u3002\u56e0\u6b64\u589e\u52a0\u6539\u62e6\u622a\u5668\u7528\u4e8e\u5ba2\u6237\u7aef\u8ba4\u8bc1&#xff0c;\u5176\u903b\u8f91\u6d41\u7a0b\u548cOAuth2AuthorizationEndpointFilter\u524d\u534a\u90e8\u5206\u6709\u5f88\u5927\u7684\u76f8\u4f3c&#xff0c;\u90fd\u662f\u4f7f\u7528AuthenticationConverter\u8f6c\u6362\u53c2\u6570&#xff0c;\u7136\u540eAuthenticationProvider\u8fdb\u884c\u9a8c\u8bc1\u3002\u8fd9\u5757\u5177\u4f53\u4f1a\u5728\u300a\u7cfb\u5217\u4e4b\u5341\u4e94 &#8211; \u9ad8\u7ea7\u7279\u6027\u2013\u5ba2\u6237\u7aef\u8ba4\u8bc1\u65b9\u5f0f\u300b\u4e2d\u8be6\u7ec6\u8bf4\u660e\u3002<\/p>\n<p>\u7ed3\u8bed&#xff1a;\u672c\u7ae0\u6211\u4eec\u5bf9Spring Authrization Server\u5982\u4f55\u5b9e\u73b0\u6388\u6743\u7801\u6a21\u5f0f\u4ee5\u53ca\u81ea\u5b9a\u4e49\u5ba2\u6237\u7aef\u4fe1\u606f\u8fdb\u884c\u6e90\u7801\u89e3\u6790&#xff0c;\u5e76\u4e86\u89e3\u4e86\u51e0\u4e2a\u5173\u952e\u7684Filter\u8fc7\u6ee4\u5668\u3002\u6709\u4e86\u8fd9\u4e2a\u57fa\u7840&#xff0c;\u5bf9\u63a5\u4e0b\u6765\u6211\u4eec\u5b9e\u73b0\u66f4\u4e3a\u9ad8\u7ea7\u7684\u6388\u6743\u670d\u52a1\u5668\u529f\u80fd&#xff0c;\u5e76\u4e86\u89e3\u5b9e\u73b0\u539f\u7406\u5c31\u53d8\u5f97\u66f4\u4e3a\u5bb9\u6613\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u672c\u7ae0\u6211\u4eec\u5bf9Spring Authrization Server\u5982\u4f55\u5b9e\u73b0\u6388\u6743\u7801\u6a21\u5f0f\u4ee5\u53ca\u81ea\u5b9a\u4e49\u5ba2\u6237\u7aef\u4fe1\u606f\u8fdb\u884c\u6e90\u7801\u89e3\u6790\uff0c\u5e76\u4e86\u89e3\u4e86\u51e0\u4e2a\u5173\u952e\u7684Filter\u8fc7\u6ee4\u5668\u3002\u6709\u4e86\u8fd9\u4e2a\u57fa\u7840\uff0c\u5bf9\u63a5\u4e0b\u6765\u6211\u4eec\u5b9e\u73b0\u66f4\u4e3a\u9ad8\u7ea7\u7684\u6388\u6743\u670d\u52a1\u5668\u529f\u80fd\uff0c\u5e76\u4e86\u89e3\u5b9e\u73b0\u539f\u7406\u5c31\u53d8\u5f97\u66f4\u4e3a\u5bb9\u6613\u3002_authenticationconverter<\/p>\n","protected":false},"author":2,"featured_media":28051,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1188,1192,1189,2247,1190],"topic":[],"class_list":["post-28062","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-oauth2","tag-sas","tag-springsecurity6","tag-2247","tag-1190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668-Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/28062.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668-Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u672c\u7ae0\u6211\u4eec\u5bf9Spring Authrization Server\u5982\u4f55\u5b9e\u73b0\u6388\u6743\u7801\u6a21\u5f0f\u4ee5\u53ca\u81ea\u5b9a\u4e49\u5ba2\u6237\u7aef\u4fe1\u606f\u8fdb\u884c\u6e90\u7801\u89e3\u6790\uff0c\u5e76\u4e86\u89e3\u4e86\u51e0\u4e2a\u5173\u952e\u7684Filter\u8fc7\u6ee4\u5668\u3002\u6709\u4e86\u8fd9\u4e2a\u57fa\u7840\uff0c\u5bf9\u63a5\u4e0b\u6765\u6211\u4eec\u5b9e\u73b0\u66f4\u4e3a\u9ad8\u7ea7\u7684\u6388\u6743\u670d\u52a1\u5668\u529f\u80fd\uff0c\u5e76\u4e86\u89e3\u5b9e\u73b0\u539f\u7406\u5c31\u53d8\u5f97\u66f4\u4e3a\u5bb9\u6613\u3002_authenticationconverter\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/28062.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-19T14:41:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144105-6803b60162fdc.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/28062.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/28062.html\",\"name\":\"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668-Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-19T14:41:09+00:00\",\"dateModified\":\"2025-04-19T14:41:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/28062.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/28062.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/28062.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668--Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668-Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/28062.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668-Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u672c\u7ae0\u6211\u4eec\u5bf9Spring Authrization Server\u5982\u4f55\u5b9e\u73b0\u6388\u6743\u7801\u6a21\u5f0f\u4ee5\u53ca\u81ea\u5b9a\u4e49\u5ba2\u6237\u7aef\u4fe1\u606f\u8fdb\u884c\u6e90\u7801\u89e3\u6790\uff0c\u5e76\u4e86\u89e3\u4e86\u51e0\u4e2a\u5173\u952e\u7684Filter\u8fc7\u6ee4\u5668\u3002\u6709\u4e86\u8fd9\u4e2a\u57fa\u7840\uff0c\u5bf9\u63a5\u4e0b\u6765\u6211\u4eec\u5b9e\u73b0\u66f4\u4e3a\u9ad8\u7ea7\u7684\u6388\u6743\u670d\u52a1\u5668\u529f\u80fd\uff0c\u5e76\u4e86\u89e3\u5b9e\u73b0\u539f\u7406\u5c31\u53d8\u5f97\u66f4\u4e3a\u5bb9\u6613\u3002_authenticationconverter","og_url":"https:\/\/www.wsisp.com\/helps\/28062.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-19T14:41:09+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419144105-6803b60162fdc.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/28062.html","url":"https:\/\/www.wsisp.com\/helps\/28062.html","name":"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668-Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-19T14:41:09+00:00","dateModified":"2025-04-19T14:41:09+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/28062.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/28062.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/28062.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u516b - \u6388\u6743\u670d\u52a1\u5668--Spring Authrization Server\u7684\u57fa\u672c\u539f\u7406"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/28062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=28062"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/28062\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/28051"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=28062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=28062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=28062"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=28062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}