{"id":32091,"date":"2025-04-22T23:41:06","date_gmt":"2025-04-22T15:41:06","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/32091.html"},"modified":"2025-04-22T23:41:06","modified_gmt":"2025-04-22T15:41:06","slug":"%e5%9f%ba%e4%ba%8espring-security-6%e7%9a%84oauth2-%e7%b3%bb%e5%88%97%e4%b9%8b%e4%ba%94-%e6%8e%88%e6%9d%83%e6%9c%8d%e5%8a%a1%e5%99%a8-%e5%bc%80%e7%af%87","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/32091.html","title":{"rendered":"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u4e94 - \u6388\u6743\u670d\u52a1\u5668--\u5f00\u7bc7"},"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 Spring Authrization Server<\/li>\n<li>2 \u81ea\u5b9a\u4e49\u6388\u6743\u670d\u52a1\u5668<\/li>\n<li>\n<ul>\n<li>2.1 oauth-server&#xff08;\u6388\u6743\u670d\u52a1\u5668&#xff09;<\/li>\n<li>2.2 oauth-client&#xff08;\u5ba2\u6237\u7aef&#xff09;<\/li>\n<li>2.3 \u6d4b\u8bd5<\/li>\n<\/ul>\n<\/li>\n<li>3 \u81ea\u52a8\u5316\u914d\u7f6e\u539f\u7406<\/li>\n<\/ul>\n<p>\u4e0a\u4e00\u7bc7\u6211\u4eec\u8bb2\u5230\u4e86\u4f5c\u4e3a\u5ba2\u6237\u7aef\u53bb\u627e\u7b2c\u4e09\u65b9\u6388\u6743\u670d\u52a1\u5668&#xff0c;\u8fd9\u4e00\u7ae0\u5f00\u59cb\u6211\u4eec\u6765\u8bb2\u8bb2\u6211\u4eec\u81ea\u5df1\u642d\u5efa\u6388\u6743\u670d\u52a1\u5668\u3002<\/p>\n<h2>1 Spring Authrization Server<\/h2>\n<p>\u65e9\u671f\u7248\u672c\u7684\u65f6\u5019&#xff0c;Spring Security 5.3.x\u7248\u672c\u91cc\u9762\u6709\u4e00\u4e2aOAuth\u6a21\u5757&#xff0c;\u91cc\u9762\u662f\u5305\u62ec\u6388\u6743\u670d\u52a1\u5668\u7684&#xff0c;\u4f46\u662f\u57282019\u5e74\u65f6&#xff0c;\u5374\u88ab\u5b98\u65b9\u79fb\u9664\u3002\u8fd9\u5c31\u9020\u6210\u539f\u5148\u4f7f\u7528Spring Security\u642d\u5efa\u7684\u6388\u6743\u670d\u52a1\u5668\u5c06\u65e0\u6cd5\u5347\u7ea7\u5230Spring Security 6\u3002\u4e0d\u8fc7\u597d\u5728Spring Security\u5b98\u65b9\u5728\u6536\u5230\u5f88\u591a\u4e0d\u6ee1\u6297\u8bae\u540e&#xff0c;\u91cd\u65b0\u63a8\u51fa\u4e00\u4e2a\u53ebSpring Authrization Server&#xff0c;\u4e0d\u8fc7\u8be5\u9879\u76ee\u5df2\u7ecf\u4e0d\u5728Spring Security\u4e0b\u9762\u3002\u6211\u4eec\u4ece\u4e0b\u56fe\u7684Spring\u5b98\u65b9\u5c31\u53ef\u4ee5\u770b\u51fa\u6765&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154102-6807b88e91399.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u73b0\u5728Spring Authrization Server\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u9879\u76ee&#xff0c;\u4f46\u662f\u5176\u5b9e\u8fd8\u662f\u8131\u79bb\u4e0d\u4e86Spring Security&#xff0c;\u56e0\u4e3a\u4f60\u4f1a\u53d1\u73b0\u5f15\u5165Spring Authrization Server\u5c31\u4f1a\u81ea\u52a8\u5f15\u5165Spring Security&#xff0c;\u5e76\u4e14\u4e5f\u662f\u4f7f\u7528Spring Security\u7684Filter\u94fe\u65b9\u5f0f\u3002\u8bdd\u4e0d\u591a\u8bf4&#xff0c;\u8bb2\u5b8c\u80cc\u666f&#xff0c;\u6211\u4eec\u5f00\u59cb\u505a\u4e00\u4e2a\u5165\u95e8\u793a\u4f8b<\/p>\n<h2>2 \u81ea\u5b9a\u4e49\u6388\u6743\u670d\u52a1\u5668<\/h2>\n<p>\u4ee3\u7801\u53c2\u8003lesson02\u5b50\u6a21\u5757&#xff0c;\u5176\u4e2d\u8be5\u5b50\u6a21\u5757\u67092\u4e2a\u5b50\u6a21\u5757&#xff0c;\u5206\u522b\u662f&#xff1a;oauth-server\u548coauth-client&#xff0c;\u4ed6\u4eec\u5206\u522b\u4ee3\u8868oauth\u7684\u6388\u6743\u670d\u52a1\u5668\u548coauth\u7684\u5ba2\u6237\u7aef\u3002<\/p>\n<h3>2.1 oauth-server&#xff08;\u6388\u6743\u670d\u52a1\u5668&#xff09;<\/h3>\n<p>\u4ee3\u7801\u53c2\u8003oauth-server\u5b50\u6a21\u5757<\/p>\n<p>1&#xff09;\u5728lesson02\u5b50\u6a21\u5757\u4e0b&#xff0c;\u65b0\u5efaoauth-server\u5b50\u6a21\u5757&#xff0c;\u5176pom\u5f15\u5165\u4f9d\u8d56&#xff1a;<\/p>\n<p><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependencies<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>org.springframework.boot<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>spring-boot-starter-web<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>org.springframework.security<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>spring-security-oauth2-authorization-server<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependencies<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>2&#xff09;\u5728resources\u65b0\u5efaapplication.yml&#xff0c;\u4ece\u5b98\u65b9demo\u6284\u4e00\u4e0b\u914d\u7f6e&#xff1a;<\/p>\n<p><span class=\"token key atrule\">server<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">port<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">9000<\/span><\/p>\n<p><span class=\"token key atrule\">logging<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">level<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">org.springframework.security<\/span><span class=\"token punctuation\">:<\/span> trace<\/p>\n<p><span class=\"token key atrule\">spring<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">security<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u4f7f\u7528security\u914d\u7f6e\u6388\u6743\u670d\u52a1\u5668\u7684\u767b\u5f55\u7528\u6237\u548c\u5bc6\u7801<\/span><br \/>\n    <span class=\"token key atrule\">user<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> user<br \/>\n      <span class=\"token key atrule\">password<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">1234<\/span><br \/>\n    <span class=\"token key atrule\">oauth2<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">authorizationserver<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># \u5ba2\u6237\u7aef\u5e94\u7528\u6ce8\u518c&#xff0c;\u8fd9\u91cc\u5c31\u7c7b\u4f3c\u6211\u4eec\u5728gitee\u4e0a\u9762\u6ce8\u518c\u81ea\u5df1\u7684\u5e94\u7528\u4e00\u6837<\/span><br \/>\n        <span class=\"token key atrule\">client<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token comment\"># \u5ba2\u6237\u7aef\u540d\u79f0<\/span><br \/>\n          <span class=\"token key atrule\">oidc-client<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token key atrule\">registration<\/span><span class=\"token punctuation\">:<\/span><br \/>\n              <span class=\"token comment\"># \u5ba2\u6237\u7aefid<\/span><br \/>\n              <span class=\"token key atrule\">client-id<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;oidc-client&#034;<\/span><br \/>\n              <span class=\"token comment\"># \u5ba2\u6237\u7aefsecret<\/span><br \/>\n              <span class=\"token key atrule\">client-secret<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;{noop}secret&#034;<\/span><br \/>\n              <span class=\"token comment\"># \u5ba2\u6237\u7aef\u9a8c\u8bc1\u65b9\u6cd5<\/span><br \/>\n              <span class=\"token key atrule\">client-authentication-methods<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;client_secret_basic&#034;<\/span><br \/>\n              <span class=\"token comment\"># \u6388\u6743\u6a21\u5f0f-\u8fd9\u91cc\u4f7f\u7528\u6388\u6743\u7801\u6a21\u5f0f<\/span><br \/>\n              <span class=\"token key atrule\">authorization-grant-types<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;authorization_code&#034;<\/span><br \/>\n                <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;refresh_token&#034;<\/span><br \/>\n              <span class=\"token comment\"># \u56de\u8c03\u5730\u5740<\/span><br \/>\n              <span class=\"token key atrule\">redirect-uris<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token comment\"># \u6ce8\u610f&#xff0c;\u8be5url\u5728\u6b64\u7248\u672c\u4e2d\u4e0d\u80fd\u4f7f\u7528127.0.0.1&#xff0c;\u9700\u8981\u5728host\u4e2d\u914d\u7f6e\u57df\u540d\u6620\u5c04&#xff0c;\u6b64\u5904\u4f7f\u7528localhost<\/span><br \/>\n                <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;http:\/\/localhost:8080\/login\/oauth2\/code\/oidc-client&#034;<\/span><br \/>\n              <span class=\"token comment\"># \u5ba2\u6237\u7aef\u9996\u9875<\/span><br \/>\n              <span class=\"token key atrule\">post-logout-redirect-uris<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token comment\"># \u6ce8\u610f&#xff0c;\u8be5url\u5728\u6b64\u7248\u672c\u4e2d\u4e0d\u80fd\u4f7f\u7528127.0.0.1&#xff0c;\u9700\u8981\u5728host\u4e2d\u914d\u7f6e\u57df\u540d\u6620\u5c04&#xff0c;\u6b64\u5904\u4f7f\u7528localhost<\/span><br \/>\n                <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;http:\/\/localhost:8080\/&#034;<\/span><br \/>\n              <span class=\"token comment\"># \u6388\u6743\u8303\u56f4<\/span><br \/>\n              <span class=\"token key atrule\">scopes<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token comment\"># \u7528\u6237\u552f\u4e00\u6807\u8bc6<\/span><br \/>\n                <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;openid&#034;<\/span><br \/>\n                <span class=\"token comment\"># \u7528\u6237\u4fe1\u606f<\/span><br \/>\n                <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token string\">&#034;profile&#034;<\/span><br \/>\n            <span class=\"token comment\"># \u662f\u5426\u9700\u8981\u6388\u6743\u786e\u8ba4<\/span><br \/>\n            <span class=\"token key atrule\">require-authorization-consent<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token boolean important\">true<\/span><\/p>\n<p>3&#xff09;\u65b0\u5efa\u542f\u52a8\u4e86Oauth2Lesson02ServerApplication&#xff0c;\u5e76\u542f\u52a8\u9879\u76ee<\/p>\n<p><span class=\"token annotation punctuation\">&#064;SpringBootApplication<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Oauth2Lesson02ServerApplication<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">SpringApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Oauth2Lesson02ServerApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> args<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><\/p>\n<h3>2.2 oauth-client&#xff08;\u5ba2\u6237\u7aef&#xff09;<\/h3>\n<p>\u4ee3\u7801\u53c2\u8003oauth-client\u5b50\u6a21\u5757<\/p>\n<p>1&#xff09;oauth-client\u5b50\u6a21\u5757&#xff0c;\u5176pom\u5f15\u5165\u4f9d\u8d56&#xff08;oauth-client\u5b50\u6a21\u5757\u57fa\u672c\u4e0a\u6284lesson01\u5b50\u6a21\u5757&#xff0c;\u53ea\u662f\u5176\u4e2d\u914d\u7f6e\u548cController\u7565\u5fae\u4fee\u6539&#xff09;<\/p>\n<p><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependencies<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>org.springframework.boot<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>spring-boot-starter-web<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>org.springframework.boot<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>spring-boot-starter-oauth2-client<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependencies<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>2&#xff09;\u5728resources\u5305\u4e0b&#xff0c;\u65b0\u5efaapplication.yml&#xff0c;\u914d\u7f6e\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token key atrule\">spring<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">application<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> oauth<span class=\"token punctuation\">&#8211;<\/span>client<\/p>\n<p>  <span class=\"token key atrule\">security<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">oauth2<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">client<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token key atrule\">registration<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">oidc-client<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u6ce8\u518c\u5e94\u7528\u540e\u7684Client ID&#xff0c;\u8fd9\u91cc\u5bf9\u5e94oauth-server\u7684client-id<\/span><br \/>\n            <span class=\"token key atrule\">clientId<\/span><span class=\"token punctuation\">:<\/span> oidc<span class=\"token punctuation\">&#8211;<\/span>client<br \/>\n            <span class=\"token comment\"># \u6ce8\u518c\u5e94\u7528\u540e\u7684Client Secret&#xff0c;\u8fd9\u91cc\u5bf9\u5e94oauth-server\u7684client-secret<\/span><br \/>\n            <span class=\"token key atrule\">clientSecret<\/span><span class=\"token punctuation\">:<\/span> secret<br \/>\n            <span class=\"token comment\"># \u6388\u6743\u7801\u6a21\u5f0f<\/span><br \/>\n            <span class=\"token key atrule\">authorizationGrantType<\/span><span class=\"token punctuation\">:<\/span> authorization_code<br \/>\n            <span class=\"token comment\"># \u56de\u8c03\u5730\u5740&#xff0c;\u8fd9\u91cc\u5bf9\u5e94oauth-server\u7684redirect-uris<\/span><br \/>\n            <span class=\"token key atrule\">redirectUri<\/span><span class=\"token punctuation\">:<\/span> http<span class=\"token punctuation\">:<\/span>\/\/localhost<span class=\"token punctuation\">:<\/span>8080\/login\/oauth2\/code\/oidc<span class=\"token punctuation\">&#8211;<\/span>client<br \/>\n            <span class=\"token comment\"># \u6388\u6743\u8bbf\u95ee<\/span><br \/>\n            <span class=\"token key atrule\">scope<\/span><span class=\"token punctuation\">:<\/span><br \/>\n              <span class=\"token punctuation\">&#8211;<\/span> openid<br \/>\n              <span class=\"token punctuation\">&#8211;<\/span> profile<br \/>\n            <span class=\"token comment\"># \u5e94\u7528\u7684provider&#xff0c;\u6ce8\u610f&#xff0c;\u8fd9\u4e2a\u540d\u79f0\u53ef\u4ee5\u968f\u4fbf\u547d\u540d&#xff0c;\u4f46\u662f\u5fc5\u987b\u4e0e\u4e0b\u9762\u7684provider\u4fdd\u6301\u4e00\u81f4<\/span><br \/>\n            <span class=\"token key atrule\">provider<\/span><span class=\"token punctuation\">:<\/span> myserverprovider<br \/>\n        <span class=\"token key atrule\">provider<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">myserverprovider<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u81ea\u5efa\u8ba4\u8bc1\u6388\u6743\u5730\u5740&#xff0c;\u4e4b\u6240\u4ee5\u91c7\u7528\u4e0d\u540c\u57df\u540d\u662f\u4e3a\u4e86\u9632\u6b62Cookie\u8986\u76d6\u95ee\u9898<\/span><br \/>\n            <span class=\"token key atrule\">authorizationUri<\/span><span class=\"token punctuation\">:<\/span> http<span class=\"token punctuation\">:<\/span>\/\/oauth<span class=\"token punctuation\">&#8211;<\/span>server<span class=\"token punctuation\">:<\/span>9000\/oauth2\/authorize<br \/>\n            <span class=\"token comment\"># \u81ea\u5efa\u8ba4\u8bc1\u83b7\u53d6access_token\u5730\u5740&#xff0c;\u4e4b\u6240\u4ee5\u91c7\u7528\u4e0d\u540c\u57df\u540d\u662f\u4e3a\u4e86\u9632\u6b62Cookie\u8986\u76d6\u95ee\u9898<\/span><br \/>\n            <span class=\"token key atrule\">tokenUri<\/span><span class=\"token punctuation\">:<\/span> http<span class=\"token punctuation\">:<\/span>\/\/oauth<span class=\"token punctuation\">&#8211;<\/span>server<span class=\"token punctuation\">:<\/span>9000\/oauth2\/token<br \/>\n            <span class=\"token comment\"># \u9a8c\u8bc1JWT\u7b7e\u540d&#xff0c;\u4e4b\u6240\u4ee5\u91c7\u7528\u4e0d\u540c\u57df\u540d\u662f\u4e3a\u4e86\u9632\u6b62Cookie\u8986\u76d6\u95ee\u9898<\/span><br \/>\n            <span class=\"token key atrule\">jwkSetUri<\/span><span class=\"token punctuation\">:<\/span> http<span class=\"token punctuation\">:<\/span>\/\/oauth<span class=\"token punctuation\">&#8211;<\/span>server<span class=\"token punctuation\">:<\/span>9000\/oauth2\/jwks<\/p>\n<p>3&#xff09;\u5148\u7535\u8111\u7684host\u6587\u4ef6&#xff0c;\u914d\u7f6e\u5982\u4e0b\u57df\u540d\u6620\u5c04&#xff1a;<\/p>\n<p>127.0.0.1       localhost oauth-server<\/p>\n<p>4&#xff09;\u5728config\u5305\u4e0b\u9762&#xff0c;\u521b\u5efaSecurityConfig\u914d\u7f6e\u7c7b<\/p>\n<p><span class=\"token annotation punctuation\">&#064;Configuration<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">SecurityConfig<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">SecurityFilterChain<\/span> <span class=\"token function\">filterChain<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">HttpSecurity<\/span> http<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throws<\/span> <span class=\"token class-name\">Exception<\/span><span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u6240\u6709\u8bbf\u95ee\u5fc5\u987b\u8ba4\u8bc1<\/span><br \/>\n        http<span class=\"token punctuation\">.<\/span><span class=\"token function\">authorizeHttpRequests<\/span><span class=\"token punctuation\">(<\/span>auth<span class=\"token operator\">-&gt;<\/span>auth<span class=\"token punctuation\">.<\/span><span class=\"token function\">anyRequest<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">authenticated<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u9ed8\u8ba4\u91c7\u7528oauth2Login\u767b\u5f55<\/span><br \/>\n        http<span class=\"token punctuation\">.<\/span><span class=\"token function\">oauth2Login<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Customizer<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">withDefaults<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> http<span class=\"token punctuation\">.<\/span><span class=\"token function\">build<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>5&#xff09;\u5728controller\u5305\u4e0b\u9762&#xff0c;\u65b0\u5efaOAuth2LoginController\u4f5c\u4e3a\u6d4b\u8bd5\u63a5\u53e3<\/p>\n<p><span class=\"token annotation punctuation\">&#064;RestController<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">OAuth2LoginController<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ http:\/\/localhost:8080\/demo<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;GetMapping<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/demo&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">String<\/span> <span class=\"token function\">demo<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;demo&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>6&#xff09;\u65b0\u5efa\u542f\u52a8\u7c7bOauth2Lesson02ClientApplication&#xff0c;\u5e76\u542f\u52a8\u9879\u76ee<\/p>\n<p><span class=\"token annotation punctuation\">&#064;SpringBootApplication<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Oauth2Lesson02ClientApplication<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">SpringApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Oauth2Lesson02ClientApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> args<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><\/p>\n<h3>2.3 \u6d4b\u8bd5<\/h3>\n<p>1&#xff09;\u6253\u5f00\u6d4f\u89c8\u5668&#xff0c;\u8bbf\u95ee&#xff1a;http:\/\/localhost:8080\/demo \u5c06\u4f1a\u81ea\u52a8\u8df3\u8f6c\u5230http:\/\/oauth-server:9000\/login &#xff08;\u8fd9\u4e00\u6b65\u548c\u6211\u4eec\u7cfb\u52173\u4e2d\u8df3\u8f6c\u5230gitee\u7684\u767b\u5f55\u754c\u9762\u4e00\u6837&#xff09;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154103-6807b88f28ae2.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>2&#xff09;\u8f93\u5165\u767b\u5f55\u8d26\u53f7\u5bc6\u7801&#xff0c;\u6211\u4eec\u5728oauth-server\u914d\u7f6e\u4e86user\u548c1234\u3002\u8fd9\u65f6\u5019\u5c31\u4f1a\u8df3\u8f6c\u5982\u4e0b\u5730\u5740&#xff0c;\u5176\u5b9e\u548c\u6211\u4eec\u7cfb\u52172\u4e00\u6837&#xff0c;\u8c03\u6574\u5230\u6388\u6743\u9875\u9762 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154103-6807b88f6e4c3.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u6388\u6743\u9875\u9762&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154103-6807b88fcd98a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> 3&#xff09;\u786e\u8ba4\u6388\u6743\u4e4b\u540e&#xff0c;\u8c03\u6574\u5230oauth-client\u7684demo\u63a5\u53e3&#xff0c;\u8fd4\u56dedemo\u5b57\u7b26\u4e32 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154104-6807b8900ab27.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>4&#xff09;\u4ece\u4e0a\u9762\u8fc7\u7a0b&#xff0c;\u6211\u4eec\u5df2\u7ecf\u642d\u5efa\u5b8c\u6700\u7b80\u5355\u7684\u6388\u6743\u670d\u52a1\u5668&#xff0c;\u4e5f\u662f\u4f7f\u7528\u6388\u6743\u7801\u6a21\u5f0f\u3002\u4ece\u4ee3\u7801\u4e2d&#xff0c;\u6211\u4eec\u7684\u6388\u6743\u670d\u52a1\u5668\u53ea\u662f\u505a\u4e86yaml\u914d\u7f6e&#xff0c;\u5e76\u6ca1\u6709\u5176\u5b83\u4ee3\u7801&#xff0c;\u5c31\u53ef\u4ee5\u5efa\u7acb\u4e00\u4e2a\u6388\u6743\u670d\u52a1\u5668&#xff0c;\u54ea\u4e9b\u6388\u6743\u5730\u5740&#xff0c;token\u5730\u5740\u662f\u600e\u4e48\u6765\u7684&#xff0c;\u8bbf\u95ee\u6d41\u7a0b\u662f\u4ec0\u4e48&#xff0c;Spring Authrization Server\u9ed8\u8ba4\u4e3a\u6211\u4eec\u505a\u4e86\u4ec0\u4e48&#xff1f;\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u6765\u521d\u6b65\u4e86\u89e3\u4e00\u4e0b\u3002<\/p>\n<h2>3 \u81ea\u52a8\u5316\u914d\u7f6e\u539f\u7406<\/h2>\n<p>1&#xff09;\u81ea\u52a8\u5316\u914d\u7f6e\u90a3\u4e48\u6700\u5148\u627e\u7684\u5f53\u7136\u662fspring-boot-autoconfigure\u3002\u6211\u4eec\u53d1\u73b0\u6709\u4e00\u4e2aOAuth2AuthorizationServerAutoConfiguration&#xff0c;\u8be5\u7c7b\u91cc\u9762\u6709\u4e24\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u5b50\u914d\u7f6e&#xff1a;OAuth2AuthorizationServerConfiguration\u548cOAuth2AuthorizationServerWebSecurityConfiguration <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154104-6807b89034657.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>2&#xff09;\u4e0b\u9762\u6211\u4eec\u5148\u6765\u770bOAuth2AuthorizationServerConfiguration\u8fd9\u4e2a\u7c7b&#xff1a;\u7b2c\u4e00\u4e2apropertiesMapper\u5c31\u89e3\u91ca\u4e86\u4e3a\u4ec0\u4e48\u6211\u4eec\u5728yaml\u6587\u4ef6\u505a\u914d\u7f6e\u4f1a\u88ab\u8bfb\u53d6\u5230&#xff1b;\u7b2c\u4e8c\u4e2aRegisteredClientRepository\u4e5f\u5c31\u662f\u4f1a\u4eceyaml\u6587\u4ef6\u4e2d\u6ce8\u518c\u4e00\u4e2a\u5ba2\u6237\u7aef\u5e94\u7528&#xff1b;\u7b2c\u4e09\u4e2aAuthorizationServerSettings\u5c31\u662f\u914d\u7f6e\u6388\u6743\u670d\u52a1\u5668\u8bbf\u95ee\u7aef\u70b9&#xff1b;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154104-6807b8906d01c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>3&#xff09;\u6211\u4eec\u518d\u770b\u770bAuthorizationServerSettings&#xff0c;\u91cc\u9762\u6709\u4e00\u4e2abuilder&#xff0c;\u5c31\u662f\u521d\u59cb\u5316\u9ed8\u8ba4\u7684\u7aef\u53e3\u914d\u7f6e&#xff0c;\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u5728\u5ba2\u6237\u7aef\u914d\u7f6e\u7684\u83b7\u53d6code\u3001token\u548cjwks\u7684\u63a5\u53e3\u662f\u600e\u4e48\u6765\u7684&#xff0c;\u5c31\u662f\u8fd9\u91cc\u914d\u7f6e\u7684\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154104-6807b890c2529.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>4&#xff09;\u518d\u56de\u5230OAuth2AuthorizationServerAutoConfiguration&#xff0c;\u6211\u4eec\u6765\u770b\u770b\u53e6\u5916\u4e00\u4e2a\u914d\u7f6e\u7c7bOAuth2AuthorizationServerWebSecurityConfiguration\u3002\u5982\u4e0b\u56fe&#xff0c;\u719f\u6089\u7684\u5473\u9053\u53c8\u6765\u4e86&#xff0c;\u914d\u7f6e\u4e86\u4e24\u6761Filter\u94fe\u8def&#xff0c;\u4e00\u6761\u662f\u914d\u7f6e\u6388\u6743\u670d\u52a1\u5668&#xff0c;\u4e00\u6761\u662f\u914d\u7f6eSecurity\u3002\u8fd9\u5c31\u89e3\u91ca\u6211\u4eec\u8bbf\u95ee\u6388\u6743\u670d\u52a1\u5668\u65f6&#xff0c;\u8981\u5148\u767b\u5f55&#xff0c;\u800c\u767b\u9646\u5c31\u662fSecurity\u7684\u914d\u7f6e\u3002\u800c\u914d\u7f6e\u6388\u6743\u670d\u52a1\u5668\u7684Filter\u94fe\u8def\u5c31\u662f\u5bf9\u6388\u6743\u670d\u52a1\u5668\u7684\u914d\u7f6e&#xff0c;\u8fd9\u4e2aFilter\u6211\u4eec\u540e\u7eed\u518d\u7ec6\u8bb2&#xff0c;\u8fd9\u91cc\u77e5\u9053\u5176\u539f\u56e0\u5373\u53ef\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154104-6807b890ed658.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>5&#xff09;\u4ece\u8fd9\u51e0\u4e2a\u57fa\u672c\u7684\u81ea\u52a8\u914d\u7f6e\u7c7b&#xff0c;\u6211\u4eec\u5927\u6982\u4e86\u89e3\u4e00\u4e0b\u51e0\u4e2a\u70b9&#xff1a;<\/p>\n<ul>\n<li>spring boot\u81ea\u52a8\u914d\u7f6e&#xff0c;\u4f1a\u8bfb\u53d6yaml\u6587\u4ef6&#xff0c;\u5e76\u5c06yaml\u6587\u4ef6\u7684\u914d\u7f6e\u8bbe\u7f6e\u5230\u6388\u6743\u670d\u52a1\u5668\u548cSpring Security\u7684\u914d\u7f6eFilter\u91cc\u9762<\/li>\n<li>\u6388\u6743\u670d\u52a1\u5668\u4e5f\u662f\u914d\u7f6e\u4e00\u6761Filter\u94fe\u8def&#xff0c;\u4f46\u662f\u8fd9\u6761Filter\u94fe\u8def\u4e0eSpring Security\u7684Filter\u94fe\u8def\u662f\u5206\u5f00\u7684\u3002\u5982\u679c\u6211\u4eec\u8981\u81ea\u5b9a\u4e49&#xff0c;\u90a3\u4e48\u5c31\u8981\u81ea\u5b9a\u4e49\u6388\u6743\u670d\u52a1\u5668\u7684Filter\u94fe\u8def<\/li>\n<li>\u5ba2\u6237\u7aef\u5e94\u7528\u6ce8\u518c\u53ef\u4ee5\u901a\u8fc7RegisteredClientRepository\u8fdb\u884c\u6ce8\u518c&#xff0c;\u76ee\u524d\u770b\u5176\u7ee7\u627f\u7c7b&#xff0c;\u4e5f\u662f\u6709\u5185\u5b58\u548c\u6570\u636e\u5e93\u4e24\u79cd\u6a21\u5f0f<\/li>\n<\/ul>\n<p>\u7ed3\u8bed&#xff1a;\u5230\u76ee\u524d\u4e3a\u6b62&#xff0c;\u6211\u4eec\u642d\u5efa\u4e86\u81ea\u5df1\u4e00\u4e2a\u6388\u6743\u670d\u52a1\u5668&#xff0c;\u5e76\u9a8c\u8bc1\u6210\u529f\u3002\u4e5f\u521d\u6b65\u4e86\u89e3Spring Boot\u4e3a\u6211\u4eec\u505a\u4e86\u54ea\u4e9b\u81ea\u52a8\u5316\u914d\u7f6e\u3002\u7aa5\u63a2\u4e86Spring Authrization Server\u7684\u914d\u7f6e\u65b9\u6cd5&#xff0c;\u90a3\u4e48\u63a5\u4e0b\u6765\u51e0\u7ae0&#xff0c;\u6211\u4eec\u5c06\u8bb2\u4e00\u4e0bSpring Authrization Server\u7684\u76f8\u5173\u914d\u7f6e&#xff0c;\u5e76\u4e86\u89e3\u5176\u539f\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e23\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u4ee3\u7801\u53c2\u8003lesson02\u5b50\u6a21\u5757\uff0c\u5176\u4e2d\u8be5\u5b50\u6a21\u5757\u67092\u4e2a\u5b50\u6a21\u5757\uff0c\u5206\u522b\u662f\uff1aoauth-server\u548coauth-client\uff0c\u4ed6\u4eec\u5206\u522b\u4ee3\u8868oauth\u7684\u6388\u6743\u670d\u52a1\u5668\u548coauth\u7684\u5ba2\u6237\u7aef\u3002_spring security6 oauth2<\/p>\n","protected":false},"author":2,"featured_media":32082,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1188,101,1189,1190,2596],"topic":[],"class_list":["post-32091","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-oauth2","tag-spring","tag-springsecurity6","tag-1190","tag-2596"],"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\u4e94 - \u6388\u6743\u670d\u52a1\u5668-\u5f00\u7bc7 - \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\/32091.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\u4e94 - \u6388\u6743\u670d\u52a1\u5668-\u5f00\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e23\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u4ee3\u7801\u53c2\u8003lesson02\u5b50\u6a21\u5757\uff0c\u5176\u4e2d\u8be5\u5b50\u6a21\u5757\u67092\u4e2a\u5b50\u6a21\u5757\uff0c\u5206\u522b\u662f\uff1aoauth-server\u548coauth-client\uff0c\u4ed6\u4eec\u5206\u522b\u4ee3\u8868oauth\u7684\u6388\u6743\u670d\u52a1\u5668\u548coauth\u7684\u5ba2\u6237\u7aef\u3002_spring security6 oauth2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/32091.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-22T15:41:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154102-6807b88e91399.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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32091.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/32091.html\",\"name\":\"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u4e94 - \u6388\u6743\u670d\u52a1\u5668-\u5f00\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-22T15:41:06+00:00\",\"dateModified\":\"2025-04-22T15:41:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/32091.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/32091.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32091.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\u4e94 - \u6388\u6743\u670d\u52a1\u5668--\u5f00\u7bc7\"}]},{\"@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\u4e94 - \u6388\u6743\u670d\u52a1\u5668-\u5f00\u7bc7 - \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\/32091.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u4e94 - \u6388\u6743\u670d\u52a1\u5668-\u5f00\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e23\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u4ee3\u7801\u53c2\u8003lesson02\u5b50\u6a21\u5757\uff0c\u5176\u4e2d\u8be5\u5b50\u6a21\u5757\u67092\u4e2a\u5b50\u6a21\u5757\uff0c\u5206\u522b\u662f\uff1aoauth-server\u548coauth-client\uff0c\u4ed6\u4eec\u5206\u522b\u4ee3\u8868oauth\u7684\u6388\u6743\u670d\u52a1\u5668\u548coauth\u7684\u5ba2\u6237\u7aef\u3002_spring security6 oauth2","og_url":"https:\/\/www.wsisp.com\/helps\/32091.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-22T15:41:06+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250422154102-6807b88e91399.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/32091.html","url":"https:\/\/www.wsisp.com\/helps\/32091.html","name":"\u57fa\u4e8eSpring Security 6\u7684OAuth2 \u7cfb\u5217\u4e4b\u4e94 - \u6388\u6743\u670d\u52a1\u5668-\u5f00\u7bc7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-22T15:41:06+00:00","dateModified":"2025-04-22T15:41:06+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/32091.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/32091.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/32091.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\u4e94 - \u6388\u6743\u670d\u52a1\u5668--\u5f00\u7bc7"}]},{"@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\/32091","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=32091"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32091\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/32082"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=32091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=32091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=32091"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=32091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}