杭州拱墅网站建设,网站seo主要是做什么的,线上推广平台都有哪些,企业网站策划书1000字1#xff0c;OAuth2.0简介
OAuth#xff08;开发授权#xff09;是一个开放标准#xff0c;允许用户授权第三方应用访问他们存储在另外的服务提供者上的信息#xff0c;而不需要将用户名和密码提供给第三方应用或分享他们数据的所有内容。 OAuth2.0是OAuth的延续#xf…1OAuth2.0简介
OAuth开发授权是一个开放标准允许用户授权第三方应用访问他们存储在另外的服务提供者上的信息而不需要将用户名和密码提供给第三方应用或分享他们数据的所有内容。 OAuth2.0是OAuth的延续但他并不兼容OAuth1.0即它完全废除OAuth1.0。很多大公司如GoogleYahooMicrosoft等都提供了OAuth认证服 务这些都足以说明OAUTH标准逐渐成为开放资源授权的标准。 微信小程序授权登录同样也是提供OAuth认证服务。详情请看
2业务场景
某一天你想登录网站CSDN之前没有在CSDN网站注册过此时在人家的登陆页面提供了其他登录方式如下图
假设我们自己做的网站叫网站B也在上图中红框部分如下图
你恰好之前在我们的B网站上注册过账号那么现在就可以使用B网站上的账号登录在CSDN上。那么我们在B网站上做这样的一个功能就是使用OAuth2做的。
OAuth2.0包含一下几种角色
1客户端本身不存储资源需要通过资源拥有者的授权去请求资源服务器的资源。2资源拥有者通常为用户也可以是应用程序即该资源的拥有者。3授权服务器认证服务器用于服务提供商对资源拥有者的身份认证对访问资源进行授权认证成功后会给客户端发放令牌access_token作为客户端访问资源服务器的凭据。4资源服务器存储资源的服务器5客户端标识client_id6客户端密钥client_secret 为什么要有client_id和client_secret呢 因为服务提供商不能允许随便一个客户端就接入到它的授权服务器服务提供商会 给准入的接入方一个身份用于接入时的凭据。
3环境搭建 authServer-service 认证服务颁发Token
gateway-service 网关认证用户的请求 也即认证Token
member-service 会员服务资源服务 5,环境搭建
父工程pom
?xml version1.0 encodingUTF-8?project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdshop.awz/groupIdartifactIdrwShop/artifactIdversion1.0-SNAPSHOT/versionmodulesmoduleauthServer-service/modulemodulegateway-service/modulemoduleorder-service/modulemoduleauthServer-service/modulemoduleadmin-service/modulemoduleproduct-service/modulemodulecommon-service/module/modulespackagingpom/packagingparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-parent/artifactIdversion2.3.2.RELEASE/version/parentpropertiesproject.build.sourceEncodingUTF‐8/project.build.sourceEncodingproject.reporting.outputEncodingUTF‐8/project.reporting.outputEncodingjava.version1.8/java.versionmaven.compiler.source1.7/maven.compiler.sourcemaven.compiler.target1.7/maven.compiler.targetspring.cloud-versionHoxton.SR9/spring.cloud-version/propertiesdependencies!--服务注册发现--dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependencydependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-sentinel/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring.cloud-version}/versiontypepom/typescopeimport/scope/dependency!--spring-cloud-alibaba 版本控制--dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-alibaba-dependencies/artifactIdversion2.2.6.RELEASE/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementbuildpluginManagement!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --plugins!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --pluginartifactIdmaven-clean-plugin/artifactIdversion3.1.0/version/plugin!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --pluginartifactIdmaven-resources-plugin/artifactIdversion3.0.2/version/pluginpluginartifactIdmaven-compiler-plugin/artifactIdversion3.8.0/version/pluginpluginartifactIdmaven-surefire-plugin/artifactIdversion2.22.1/version/pluginpluginartifactIdmaven-jar-plugin/artifactIdversion3.0.2/version/pluginpluginartifactIdmaven-install-plugin/artifactIdversion2.5.2/version/pluginpluginartifactIdmaven-deploy-plugin/artifactIdversion2.8.2/version/plugin!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --pluginartifactIdmaven-site-plugin/artifactIdversion3.7.1/version/pluginpluginartifactIdmaven-project-info-reports-plugin/artifactIdversion3.0.0/version/plugin/plugins/pluginManagement/build
/projectauthServer-service 工程pom
?xml version1.0 encodingUTF-8?project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdrwShop/artifactIdgroupIdshop.awz/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdauthServer-service/artifactIdnameauthServer-service/name!-- FIXME change it to the projects website --urlhttp://www.example.com/urlpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingmaven.compiler.source1.7/maven.compiler.sourcemaven.compiler.target1.7/maven.compiler.target/propertiesdependencies!--Lombok引入--dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency!-- Spring Boot JPA 依赖 --dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId/dependencydependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.4.0/version/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-oauth2/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdexecutionsexecutiongoals!--可以把依赖的包都打包到生成的Jar包中--goalrepackage/goal/goals/execution/executions/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdconfigurationsource1.8/sourcetarget1.8/target/configuration/plugin/plugins/build
/project网关pom
?xml version1.0 encodingUTF-8?project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdrwShop/artifactIdgroupIdshop.awz/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdgateway-service/artifactIdnamegateway-service/name!-- FIXME change it to the projects website --urlhttp://www.example.com/urlpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingmaven.compiler.source1.7/maven.compiler.sourcemaven.compiler.target1.7/maven.compiler.targetspring.cloud-versionHoxton.SR9/spring.cloud-version/propertiesdependencies!--安全认证框架--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-security/artifactId/dependency!--security-oauth2整合--dependencygroupIdorg.springframework.security/groupIdartifactIdspring-security-oauth2-resource-server/artifactId/dependency!--oauth2--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-oauth2/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-jdbc/artifactId/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion8.0.30/version/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency!--网关--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId/dependency/dependenciesdependencyManagement!--https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E--dependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring.cloud-version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdexecutionsexecutiongoals!--可以把依赖的包都打包到生成的Jar包中--goalrepackage/goal/goals/execution/executions/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdconfigurationsource1.8/sourcetarget1.8/target/configuration/plugin/plugins/build
/project4authServer-service
sql脚本
DROP TABLE IF EXISTS oauth_refresh_token;
CREATE TABLE oauth_refresh_token (token_id varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,token blob NULL,authentication blob NULL
) ENGINE InnoDB AUTO_INCREMENT 2 CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT Dynamic;-- ----------------------------
-- Records of oauth_refresh_token
-- ----------------------------
INSERT INTO oauth_refresh_token VALUES (bbd20d647aae14322d441c3bfee18d03, 0xACED00057372004C6F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E636F6D6D6F6E2E44656661756C744578706972696E674F417574683252656672657368546F6B656E2FDF47639DD0C9B70200014C000A65787069726174696F6E7400104C6A6176612F7574696C2F446174653B787200446F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E636F6D6D6F6E2E44656661756C744F417574683252656672657368546F6B656E73E10E0A6354D45E0200014C000576616C75657400124C6A6176612F6C616E672F537472696E673B787074002438396463643534612D626663392D343964352D613332372D3834653637643030656630637372000E6A6176612E7574696C2E44617465686A81014B5974190300007870770800000186CF2F197E78, 0xACED0005737200416F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E4F417574683241757468656E7469636174696F6EBD400B02166252130200024C000D73746F7265645265717565737474003C4C6F72672F737072696E676672616D65776F726B2F73656375726974792F6F61757468322F70726F76696465722F4F4175746832526571756573743B4C00127573657241757468656E7469636174696F6E7400324C6F72672F737072696E676672616D65776F726B2F73656375726974792F636F72652F41757468656E7469636174696F6E3B787200476F72672E737072696E676672616D65776F726B2E73656375726974792E61757468656E7469636174696F6E2E416273747261637441757468656E7469636174696F6E546F6B656ED3AA287E6E47640E0200035A000D61757468656E746963617465644C000B617574686F7269746965737400164C6A6176612F7574696C2F436F6C6C656374696F6E3B4C000764657461696C737400124C6A6176612F6C616E672F4F626A6563743B787000737200266A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C654C697374FC0F2531B5EC8E100200014C00046C6973747400104C6A6176612F7574696C2F4C6973743B7872002C6A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C65436F6C6C656374696F6E19420080CB5EF71E0200014C00016371007E00047870737200136A6176612E7574696C2E41727261794C6973747881D21D99C7619D03000149000473697A65787000000001770400000001737200426F72672E737072696E676672616D65776F726B2E73656375726974792E636F72652E617574686F726974792E53696D706C654772616E746564417574686F7269747900000000000002120200014C0004726F6C657400124C6A6176612F6C616E672F537472696E673B787074003C24326124313024397A6D7A72516F485065324C76552F6369594F6837656830767054686C47306A66566E643935742F4D634C794C623974354E337A477871007E000C707372003A6F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E4F41757468325265717565737400000000000000010200075A0008617070726F7665644C000B617574686F72697469657371007E00044C000A657874656E73696F6E7374000F4C6A6176612F7574696C2F4D61703B4C000B726564697265637455726971007E000E4C00077265667265736874003B4C6F72672F737072696E676672616D65776F726B2F73656375726974792F6F61757468322F70726F76696465722F546F6B656E526571756573743B4C000B7265736F7572636549647374000F4C6A6176612F7574696C2F5365743B4C000D726573706F6E7365547970657371007E0014787200386F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E426173655265717565737436287A3EA37169BD0200034C0008636C69656E74496471007E000E4C001172657175657374506172616D657465727371007E00124C000573636F706571007E00147870740003617070737200256A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C654D6170F1A5A8FE74F507420200014C00016D71007E00127870737200116A6176612E7574696C2E486173684D61700507DAC1C31660D103000246000A6C6F6164466163746F724900097468726573686F6C6478703F400000000000067708000000080000000374000A6772616E745F7479706574000870617373776F7264740009636C69656E745F6964740003617070740008757365726E616D657400047A69796178737200256A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C65536574801D92D18F9B80550200007871007E0009737200176A6176612E7574696C2E4C696E6B656448617368536574D86CD75A95DD2A1E020000787200116A6176612E7574696C2E48617368536574BA44859596B8B7340300007870770C000000103F4000000000000174000377656278017371007E0025770C000000103F400000000000017371007E000D740009524F4C455F55534552787371007E001A3F40000000000000770800000010000000007870707371007E0025770C000000103F40000000000001740003617070787371007E0025770C000000103F40000000000000787372004F6F72672E737072696E676672616D65776F726B2E73656375726974792E61757468656E7469636174696F6E2E557365726E616D6550617373776F726441757468656E7469636174696F6E546F6B656E00000000000002120200024C000B63726564656E7469616C7371007E00054C00097072696E636970616C71007E00057871007E0003017371007E00077371007E000B0000000177040000000171007E000F7871007E0032737200176A6176612E7574696C2E4C696E6B6564486173684D617034C04E5C106CC0FB0200015A000B6163636573734F726465727871007E001A3F400000000000067708000000080000000474000D636C69656E745F73656372657474000361707071007E001C71007E001D71007E001E71007E001F71007E002071007E0021780070737200326F72672E737072696E676672616D65776F726B2E73656375726974792E636F72652E7573657264657461696C732E5573657200000000000002120200075A00116163636F756E744E6F6E457870697265645A00106163636F756E744E6F6E4C6F636B65645A001563726564656E7469616C734E6F6E457870697265645A0007656E61626C65644C000B617574686F72697469657371007E00144C000870617373776F726471007E000E4C0008757365726E616D6571007E000E7870010101017371007E0022737200116A6176612E7574696C2E54726565536574DD98509395ED875B0300007870737200466F72672E737072696E676672616D65776F726B2E73656375726974792E636F72652E7573657264657461696C732E5573657224417574686F72697479436F6D70617261746F720000000000000212020000787077040000000171007E000F78707400047A697961);SET FOREIGN_KEY_CHECKS 1;DROP TABLE IF EXISTS oauth_access_token;
CREATE TABLE oauth_access_token (token_id varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,token blob NULL,authentication_id varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,user_name varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,client_id varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,authentication blob NULL,refresh_token varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,PRIMARY KEY (authentication_id) USING BTREE
) ENGINE InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT Dynamic;-- ----------------------------
-- Records of oauth_access_token
-- ----------------------------
INSERT INTO oauth_access_token VALUES (5e45bb16fc49de6fbdbbc5272cf199f7, 0xACED0005737200436F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E636F6D6D6F6E2E44656661756C744F4175746832416363657373546F6B656E0CB29E361B24FACE0200064C00156164646974696F6E616C496E666F726D6174696F6E74000F4C6A6176612F7574696C2F4D61703B4C000A65787069726174696F6E7400104C6A6176612F7574696C2F446174653B4C000C72656672657368546F6B656E74003F4C6F72672F737072696E676672616D65776F726B2F73656375726974792F6F61757468322F636F6D6D6F6E2F4F417574683252656672657368546F6B656E3B4C000573636F706574000F4C6A6176612F7574696C2F5365743B4C0009746F6B656E547970657400124C6A6176612F6C616E672F537472696E673B4C000576616C756571007E000578707372001E6A6176612E7574696C2E436F6C6C656374696F6E7324456D7074794D6170593614855ADCE7D002000078707372000E6A6176612E7574696C2E44617465686A81014B597419030000787077080000018637437F9E787372004C6F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E636F6D6D6F6E2E44656661756C744578706972696E674F417574683252656672657368546F6B656E2FDF47639DD0C9B70200014C000A65787069726174696F6E71007E0002787200446F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E636F6D6D6F6E2E44656661756C744F417574683252656672657368546F6B656E73E10E0A6354D45E0200014C000576616C756571007E0005787074002438396463643534612D626663392D343964352D613332372D3834653637643030656630637371007E0009770800000186CF2F197E78737200256A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C65536574801D92D18F9B80550200007872002C6A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C65436F6C6C656374696F6E19420080CB5EF71E0200014C0001637400164C6A6176612F7574696C2F436F6C6C656374696F6E3B7870737200176A6176612E7574696C2E4C696E6B656448617368536574D86CD75A95DD2A1E020000787200116A6176612E7574696C2E48617368536574BA44859596B8B7340300007870770C000000103F400000000000017400037765627874000662656172657274002433633033643735392D376665362D346164322D383034332D303066303564366466353066, 743b6d0443f74879a092610739f759b6, ziya, app, 0xACED0005737200416F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E4F417574683241757468656E7469636174696F6EBD400B02166252130200024C000D73746F7265645265717565737474003C4C6F72672F737072696E676672616D65776F726B2F73656375726974792F6F61757468322F70726F76696465722F4F4175746832526571756573743B4C00127573657241757468656E7469636174696F6E7400324C6F72672F737072696E676672616D65776F726B2F73656375726974792F636F72652F41757468656E7469636174696F6E3B787200476F72672E737072696E676672616D65776F726B2E73656375726974792E61757468656E7469636174696F6E2E416273747261637441757468656E7469636174696F6E546F6B656ED3AA287E6E47640E0200035A000D61757468656E746963617465644C000B617574686F7269746965737400164C6A6176612F7574696C2F436F6C6C656374696F6E3B4C000764657461696C737400124C6A6176612F6C616E672F4F626A6563743B787000737200266A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C654C697374FC0F2531B5EC8E100200014C00046C6973747400104C6A6176612F7574696C2F4C6973743B7872002C6A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C65436F6C6C656374696F6E19420080CB5EF71E0200014C00016371007E00047870737200136A6176612E7574696C2E41727261794C6973747881D21D99C7619D03000149000473697A65787000000001770400000001737200426F72672E737072696E676672616D65776F726B2E73656375726974792E636F72652E617574686F726974792E53696D706C654772616E746564417574686F7269747900000000000002120200014C0004726F6C657400124C6A6176612F6C616E672F537472696E673B787074003C24326124313024397A6D7A72516F485065324C76552F6369594F6837656830767054686C47306A66566E643935742F4D634C794C623974354E337A477871007E000C707372003A6F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E4F41757468325265717565737400000000000000010200075A0008617070726F7665644C000B617574686F72697469657371007E00044C000A657874656E73696F6E7374000F4C6A6176612F7574696C2F4D61703B4C000B726564697265637455726971007E000E4C00077265667265736874003B4C6F72672F737072696E676672616D65776F726B2F73656375726974792F6F61757468322F70726F76696465722F546F6B656E526571756573743B4C000B7265736F7572636549647374000F4C6A6176612F7574696C2F5365743B4C000D726573706F6E7365547970657371007E0014787200386F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E426173655265717565737436287A3EA37169BD0200034C0008636C69656E74496471007E000E4C001172657175657374506172616D657465727371007E00124C000573636F706571007E00147870740003617070737200256A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C654D6170F1A5A8FE74F507420200014C00016D71007E00127870737200116A6176612E7574696C2E486173684D61700507DAC1C31660D103000246000A6C6F6164466163746F724900097468726573686F6C6478703F400000000000067708000000080000000374000A6772616E745F7479706574000870617373776F7264740009636C69656E745F6964740003617070740008757365726E616D657400047A69796178737200256A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C65536574801D92D18F9B80550200007871007E0009737200176A6176612E7574696C2E4C696E6B656448617368536574D86CD75A95DD2A1E020000787200116A6176612E7574696C2E48617368536574BA44859596B8B7340300007870770C000000103F4000000000000174000377656278017371007E0025770C000000103F400000000000017371007E000D740009524F4C455F55534552787371007E001A3F40000000000000770800000010000000007870707371007E0025770C000000103F40000000000001740003617070787371007E0025770C000000103F40000000000000787372004F6F72672E737072696E676672616D65776F726B2E73656375726974792E61757468656E7469636174696F6E2E557365726E616D6550617373776F726441757468656E7469636174696F6E546F6B656E00000000000002120200024C000B63726564656E7469616C7371007E00054C00097072696E636970616C71007E00057871007E0003017371007E00077371007E000B0000000177040000000171007E000F7871007E0032737200176A6176612E7574696C2E4C696E6B6564486173684D617034C04E5C106CC0FB0200015A000B6163636573734F726465727871007E001A3F400000000000067708000000080000000474000D636C69656E745F73656372657474000361707071007E001C71007E001D71007E001E71007E001F71007E002071007E0021780070737200326F72672E737072696E676672616D65776F726B2E73656375726974792E636F72652E7573657264657461696C732E5573657200000000000002120200075A00116163636F756E744E6F6E457870697265645A00106163636F756E744E6F6E4C6F636B65645A001563726564656E7469616C734E6F6E457870697265645A0007656E61626C65644C000B617574686F72697469657371007E00144C000870617373776F726471007E000E4C0008757365726E616D6571007E000E7870010101017371007E0022737200116A6176612E7574696C2E54726565536574DD98509395ED875B0300007870737200466F72672E737072696E676672616D65776F726B2E73656375726974792E636F72652E7573657264657461696C732E5573657224417574686F72697479436F6D70617261746F720000000000000212020000787077040000000171007E000F78707400047A697961, bbd20d647aae14322d441c3bfee18d03);SET FOREIGN_KEY_CHECKS 1;
DROP TABLE IF EXISTS oauth_client_details;
CREATE TABLE oauth_client_details (client_id varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,resource_ids varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,client_secret varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,scope varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,authorized_grant_types varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,web_server_redirect_uri varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,authorities varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,access_token_validity int NULL DEFAULT NULL,refresh_token_validity int NULL DEFAULT NULL,additional_information varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,autoapprove varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,PRIMARY KEY (client_id) USING BTREE
) ENGINE InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT Dynamic;-- ----------------------------
-- Records of oauth_client_details
-- ----------------------------
INSERT INTO oauth_client_details VALUES (app, app, $2a$10$by3F74LZAxBQLXCbESOS/eew8/7skdxvx5QdcJAMddfLISizAOXAe, web, implicit,client_credentials,authorization_code,refresh_token,password, http://www.baidu.com, ROLE_USER, NULL, NULL, NULL, NULL);SET FOREIGN_KEY_CHECKS 1;
DROP TABLE IF EXISTS oauth_client_token;
CREATE TABLE oauth_client_token (token_id varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,token blob NULL,authentication_id varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,user_name varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,client_id varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,PRIMARY KEY (authentication_id) USING BTREE
) ENGINE InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT Dynamic;-- ----------------------------
-- Records of oauth_client_token
-- ----------------------------SET FOREIGN_KEY_CHECKS 1;
DROP TABLE IF EXISTS oauth_code;
CREATE TABLE oauth_code (code varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,authentication blob NULL
) ENGINE InnoDB AUTO_INCREMENT 1 CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT Dynamic;-- ----------------------------
-- Records of oauth_code
-- ----------------------------SET FOREIGN_KEY_CHECKS 1;
DROP TABLE IF EXISTS user;
CREATE TABLE user (id int NOT NULL AUTO_INCREMENT,passwd varchar(265) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,user_name varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,user_role varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,PRIMARY KEY (id) USING BTREE
) ENGINE InnoDB AUTO_INCREMENT 2 CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT Dynamic;-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO user VALUES (1, $2a$10$9zmzrQoHPe2LvU/ciYOh7eh0vpThlG0jfVnd95t/McLyLb9t5N3zG, ziya, ADMIN);SET FOREIGN_KEY_CHECKS 1;配置文件application.yml
server:port: 9000spring:main:allow-bean-definition-overriding: trueapplication:name: auth-servicedatasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/awz_admins?serverTimezoneGMT%2B8useSSLfalsecharacterEncodingutf8username: rootpassword: 123456jackson:date-format: yyyy-MM-dd HH:mm:sstime-zone: GMT8cloud:nacos:discovery:server-addr: 127.0.0.1:8848
logging:level:shop.awz.uaa.dao: debug
# file:
# name: log/blog.logpattern:level:mybatis-plus:type-aliases-package: shop.awz.uaa.entitymapper-locations: classpath:mapper/*.xml#配置驼峰命名映射configuration:map-underscore-to-camel-case: trueAuthorizationServerConfig配置类 java
package shop.awz.uaa.config;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;import javax.sql.DataSource;
import java.util.Arrays;/*** ClassName AuthorizationServerConfig* Author 杨杰* Date 2023/2/9 12:15* Version 1.0*/Configuration
EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {Autowiredprivate UserDetailsService userDetailService;// 认证管理器Autowiredprivate AuthenticationManager authenticationManager;Autowiredprivate DataSource dataSource;Autowiredprivate JwtAccessTokenConverter accessTokenConverter;Autowiredprivate TokenStore tokenStore;Autowiredprivate ClientDetailsService clientDetailsService;//令牌管理服务Beanpublic AuthorizationServerTokenServices tokenService() {DefaultTokenServices service new DefaultTokenServices();// 客户端详情服务service.setClientDetailsService(clientDetailsService);service.setSupportRefreshToken(true);//支持刷新令牌service.setTokenStore(tokenStore);//令牌存储策略//令牌增强TokenEnhancerChain tokenEnhancerChain new TokenEnhancerChain();tokenEnhancerChain.setTokenEnhancers(Arrays.asList(accessTokenConverter));service.setTokenEnhancer(tokenEnhancerChain);service.setAccessTokenValiditySeconds(7200); // 令牌默认有效期2小时service.setRefreshTokenValiditySeconds(259200); // 刷新令牌默认有效期3天return service;}// /**
// * access_token存储器
// * 这里存储在数据库大家可以结合自己的业务场景考虑将access_token存入数据库还是redis
// */
// Bean
// public TokenStore tokenStore() {
// return new JdbcTokenStore(dataSource);
// }/*** 从数据库读取clientDetails相关配置* 有InMemoryClientDetailsService 和 JdbcClientDetailsService 两种方式选择*/Beanpublic ClientDetailsService clientDetails() {return new JdbcClientDetailsService(dataSource);}/*** 注入密码加密实现器*/Beanpublic PasswordEncoder passwordEncoder() {return new BCryptPasswordEncoder();}/*** 认证服务器Endpoints配置*/Overridepublic void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {//如果需要使用refresh_token模式则需要注入userDetailServiceendpoints.userDetailsService(userDetailService);endpoints.authenticationManager(this.authenticationManager);endpoints.tokenServices(tokenService());endpoints.tokenStore(tokenStore);}/*** 认证服务器相关接口权限管理*/Overridepublic void configure(AuthorizationServerSecurityConfigurer security) throws Exception {security.allowFormAuthenticationForClients() //如果使用表单认证则需要加上.tokenKeyAccess(permitAll()).checkTokenAccess(isAuthenticated());}/*** client存储方式此处使用jdbc存储*/Overridepublic void configure(ClientDetailsServiceConfigurer clients) throws Exception {clients.withClientDetails(clientDetails());}
}ClientDetailsServiceConfigurer用来配置客户端详情服务ClientDetailsService客户端详情信息在 这里进行初始化你能够把客户端详情信息写死在这里或者是通过数据库来存储调取详情信息。AuthorizationServerEndpointsConfigurer用来配置令牌token的访问端点和令牌服务(token services)。AuthorizationServerSecurityConfigurer用来配置令牌端点的安全约束
TokenConfig配置类java
package shop.awz.uaa.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;/*** ClassName TokenConfig* Author 杨杰* Date 2023/2/9 22:14* Version 1.0*/
Configuration
public class TokenConfig {private String SIGNING_KEY uaa123;Beanpublic TokenStore tokenStore() {//JWT令牌存储方案return new JwtTokenStore(accessTokenConverter());}Beanpublic JwtAccessTokenConverter accessTokenConverter() {JwtAccessTokenConverter converter new JwtAccessTokenConverter();converter.setSigningKey(SIGNING_KEY); //对称秘钥资源服务器使用该秘钥来验证return converter;}/* Beanpublic TokenStore tokenStore() {//使用内存存储令牌普通令牌return new InMemoryTokenStore();}*/
}这里使用的是JWT WebSecurityConfig配置类
package shop.awz.uaa.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import shop.awz.uaa.service.UserDetailServiceImpl;
/*** ClassName WebSecurityConfig* Author 杨杰* Date 2023/2/9 12:25* Version 1.0*/Configuration
EnableWebSecurity
EnableGlobalMethodSecurity(prePostEnabled true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {OverrideBean(UserDetailServiceImpl)public UserDetailsService userDetailsService(){return new UserDetailServiceImpl();}Beanpublic PasswordEncoder passwordEncoder(){return new BCryptPasswordEncoder();}/*** 认证管理* return 认证管理对象* throws Exception 认证异常信息*/OverrideBeanpublic AuthenticationManager authenticationManagerBean() throws Exception {return super.authenticationManagerBean();}Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.userDetailsService(userDetailsService()).passwordEncoder(new PasswordEncoder() {//密码加密Overridepublic String encode(CharSequence charSequence) {BCryptPasswordEncoder passwordEncoder new BCryptPasswordEncoder();return passwordEncoder.encode(charSequence);}Overridepublic boolean matches(CharSequence charSequence, String s) {BCryptPasswordEncoder passwordEncoder new BCryptPasswordEncoder();boolean res passwordEncoder.matches(charSequence, s);return res;}});}/*** http安全配置* param http http安全对象* throws Exception http安全异常信息*/Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated().and().httpBasic().and().cors().and().csrf().disable();}Overridepublic void configure(WebSecurity web) throws Exception {web.ignoring().antMatchers(/error,/static/**,/v2/api-docs/**,/swagger-resources/**,/webjars/**,/favicon.ico);}
}UserDetailServiceImpl实现类
package shop.awz.uaa.service;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import shop.awz.uaa.dao.UserMapper;
import shop.awz.uaa.entity.User;/*** ClassName UserDetailServiceImpl* Author 杨杰* Date 2023/2/9 12:11* Version 1.0*/
Service(UserDetailServiceImpl)
public class UserDetailServiceImpl implements UserDetailsService {Autowiredprivate UserMapper userMapper;Overridepublic UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {//获取本地用户
// User user userName.queryByUserName(userName);User user userMapper.selectOne(new QueryWrapperUser().eq(user_name,userName));if (user ! null) {//返回oauth2的用户return new org.springframework.security.core.userdetails.User(user.getUserName(),user.getPasswd(),AuthorityUtils.createAuthorityList(user.getPasswd()));} else {throw new UsernameNotFoundException(用户[ userName ]不存在);}}
}user实体类
package shop.awz.uaa.entity;/*** ClassName User* Author 杨杰* Date 2023/2/9 11:59* Version 1.0*/import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;Data
TableName(user)
public class User {TableIdprivate Integer id;private String passwd;private String userName;private String userRole;}usermapper
Mapper
public interface UserMapper extends BaseMapperUser {
}启动类
SpringBootApplication
EnableResourceServer
EnableDiscoveryClient
public class AuthServiceMain9000
{public static void main( String[] args ){SpringApplication.run(AuthServiceMain9000.class,args);}
}6网关
application.ymlserver:port: 80spring:application:name: gateway-servicedatasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/awz_admins?serverTimezoneGMT%2B8useSSLfalsecharacterEncodingutf8username: rootpassword: 123456jackson:date-format: yyyy-MM-dd HH:mm:sstime-zone: GMT8cloud:nacos:discovery:server-addr: 127.0.0.1:8848gateway:routes:- id: auth-routeuri: lb://auth-servicepredicates:- Path/oauth/**- id: order-routeuri: lb://order-servicepredicates:- Path/order/**- id: admin-routeuri: lb://admin-servicepredicates:- Path/admin-service/**globalcors:cors-configurations:[/**]:allow-credentials: trueallowed-methods: *allowed-origins: *allowed-headers: *TokenConfig配置类
Configuration
public class TokenConfig {private String SIGNING_KEY uaa123;Beanpublic TokenStore tokenStore() {//JWT令牌存储方案return new JwtTokenStore(accessTokenConverter());}Beanpublic JwtAccessTokenConverter accessTokenConverter() {JwtAccessTokenConverter converter new JwtAccessTokenConverter();converter.setSigningKey(SIGNING_KEY); //对称秘钥资源服务器使用该秘钥来验证return converter;}/* Beanpublic TokenStore tokenStore() {//使用内存存储令牌普通令牌return new InMemoryTokenStore();}*/
}securityConfig配置类
package shop.awz.gateway.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.config.web.server.SecurityWebFiltersOrder;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.server.resource.web.server.ServerBearerTokenAuthenticationConverter;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
import shop.awz.gateway.Manager.AccessManager;
import shop.awz.gateway.Manager.ReactiveJdbcAuthenticationManager;import javax.sql.DataSource;/*** ClassName SecurityConfig* Author 杨杰* Date 2023/2/9 12:38* Version 1.0*/
Configuration
public class SecurityConfig {private static final String MAX_AGE 18000L;Autowiredprivate DataSource dataSource;Autowiredprivate AccessManager accessManager;Autowiredprivate TokenStore tokenStore;BeanSecurityWebFilterChain webFluxSecurityFilterChain(ServerHttpSecurity http) throws Exception{//token管理器ReactiveAuthenticationManager tokenAuthenticationManager new ReactiveJdbcAuthenticationManager(tokenStore);//认证过滤器AuthenticationWebFilter authenticationWebFilter new AuthenticationWebFilter(tokenAuthenticationManager);authenticationWebFilter.setServerAuthenticationConverter(new ServerBearerTokenAuthenticationConverter());http.httpBasic().disable().csrf().disable().authorizeExchange().pathMatchers(HttpMethod.OPTIONS).permitAll().pathMatchers(HttpMethod.GET).permitAll().pathMatchers(HttpMethod.POST).permitAll().anyExchange().access(accessManager).and()//oauth2认证过滤器.addFilterAt(authenticationWebFilter, SecurityWebFiltersOrder.AUTHENTICATION);return http.build();}
}AccessManager配置类
package shop.awz.gateway.Manager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authorization.AuthorizationDecision;
import org.springframework.security.authorization.ReactiveAuthorizationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.web.server.authorization.AuthorizationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;/*** ClassName AccessManager* Author 杨杰* Date 2023/2/9 12:37* Version 1.0*/Slf4j
Component
public class AccessManager implements ReactiveAuthorizationManagerAuthorizationContext {private SetString permitAll new ConcurrentSkipListSet();private static final AntPathMatcher antPathMatcher new AntPathMatcher();public AccessManager() {permitAll.add(/);permitAll.add(/error);permitAll.add(/favicon.ico);permitAll.add(/**/v2/api-docs/**);permitAll.add(/**/swagger-resources/**);permitAll.add(/webjars/**);permitAll.add(/doc.html);permitAll.add(/swagger-ui.html);permitAll.add(/**/oauth/**);permitAll.add(/**/current/get);permitAll.add(/admin-service/**);}/*** 实现权限验证判断*/Overridepublic MonoAuthorizationDecision check(MonoAuthentication authenticationMono, AuthorizationContext authorizationContext) {ServerWebExchange exchange authorizationContext.getExchange();//请求资源String requestPath exchange.getRequest().getURI().getPath();// 是否直接放行if (permitAll(requestPath)) {return Mono.just(new AuthorizationDecision(true));}return authenticationMono.map(auth - {return new AuthorizationDecision(checkAuthorities(exchange, auth, requestPath));}).defaultIfEmpty(new AuthorizationDecision(false));}/*** 校验是否属于静态资源** param requestPath 请求路径* return*/private boolean permitAll(String requestPath) {return permitAll.stream().filter(r - antPathMatcher.match(r, requestPath)).findFirst().isPresent();}//权限校验private boolean checkAuthorities(ServerWebExchange exchange, Authentication auth, String requestPath) {if (auth instanceof OAuth2Authentication) {OAuth2Authentication athentication (OAuth2Authentication) auth;String clientId athentication.getOAuth2Request().getClientId();log.info(clientId is {}, clientId);}Object principal auth.getPrincipal();log.info(用户信息:{}, principal.toString());return true;}
}拦截器配置类
package shop.awz.gateway.Manager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken;
import reactor.core.publisher.Mono;/*** ClassName ReactiveJdbcAuthenticationManager* Author 杨杰* Date 2023/2/9 12:37* Version 1.0*/public class ReactiveJdbcAuthenticationManager implements ReactiveAuthenticationManager {Logger logger LoggerFactory.getLogger(ReactiveJdbcAuthenticationManager.class);private TokenStore tokenStore;public ReactiveJdbcAuthenticationManager(TokenStore tokenStore){this.tokenStore tokenStore;}Overridepublic MonoAuthentication authenticate(Authentication authentication) {return Mono.justOrEmpty(authentication).filter(a - a instanceof BearerTokenAuthenticationToken).cast(BearerTokenAuthenticationToken.class).map(BearerTokenAuthenticationToken::getToken).flatMap((accessToken -{logger.info(accessToken is :{},accessToken);OAuth2AccessToken oAuth2AccessToken this.tokenStore.readAccessToken(accessToken);//根据access_token从数据库获取不到OAuth2AccessTokenif(oAuth2AccessToken null){return Mono.error(new InvalidTokenException(invalid access token,please check));}else if(oAuth2AccessToken.isExpired()){return Mono.error(new InvalidTokenException(access token has expired,please reacquire token));}OAuth2Authentication oAuth2Authentication this.tokenStore.readAuthentication(accessToken);if(oAuth2Authentication null){return Mono.error(new InvalidTokenException(Access Token 无效!));}else {return Mono.just(oAuth2Authentication);}})).cast(Authentication.class);}
}启动类
SpringBootApplication
EnableDiscoveryClient
public class GateWayServiceMain80
{public static void main( String[] args ){SpringApplication.run(GateWayServiceMain80.class,args);}
}6member-serviceGetMapping(/product/{productId})
public String getProductName(PathVariable Integer productId) {return 用户基本信息;
}6测试在测试之前我们再来梳理一下流程 1用户想要登录CSDN
2用户在CSDN上选择我们的网站B进行快捷登录此时我们的网站B已经和CSDN有合作并且给我们网站B给CSND密钥。和客户端ID
3当用户选择后跳转到我们的网站B的第三方授权登录页面
4用户输入用户名或密码进行授权登录
5用户请求携带用户名和密码以及CSDN客户端的ID密钥等信息在我们的网站B上进行登录
6网关断言后将请求分到授权服务
7授权服务认证通过后响应授权码到网关
8网关响应授权码并重定向到CSDN
9CSDN获取授权码并携带授权码再次请求我们的网站B以获取access_token
这里我们为什么要获取access_token?这是因为你要获取的用户信息接口需要校验这个请求中是否包含access_token,来判断是否是合法请求这也是Oauth2协议的一个关键部分。之前的是授权码仅仅代表用户已经同意CSDN网站从我们的网站B上获取他的一些基本信息。而要获取到用户的信息还必须要有access_token。10网关断言后将请求分到授权服务
11授权服务通过后响应access_token给网关
12网关将access_token响应给CSDN
13CSDN携带access_token再次请求我们的网站B
14网关认证认证access_token是否合法是否过期等后将请求分发到资源服务器
15资源服务器将用户信息响应给网关
16网关将用户信息响应给CSDN
17CSDN就可以使用这些基本信息来登录
其中1-4部分用户是可以感知的其余的用户无法感知。
测试因为我们的网站还无法提供给CSDN做快捷登录
所以我们的模拟只能从9步开始使用密码登录模式使用postman进行测试