diff --git a/README.md b/README.md index 9789da0..ff8786c 100644 --- a/README.md +++ b/README.md @@ -64,14 +64,15 @@ Base on Spring-Boot
  • 将本地项目导入到IDE(如Intellij IDEA)中,配置Tomcat(或类似的servlet运行服务器), 并启动Tomcat(默认端口为8080); -
    -注意将项目的 contextPath(根路径) 设置为 'spring-oauth-server'.
    另: 也可通过maven package命令将项目编译为war文件(spring-oauth-server.war), - 将war放在Tomcat中并启动(注意: 这种方式需要将application.properties加入到classpath中并正确配置数据库连接信息). + 将war放在Tomcat中并启动 + 或使用命令 java -jar spring-oauth-server.war + (若要使用自定义的properties则使用 java -jar spring-oauth-server.war --spring.config.location=application.properties) +
  • -参考oauth_test.txt(位于others目录)的内容并测试之(也可在浏览器中访问相应的地址,如: http://localhost:8080/spring-oauth-server). +参考oauth_test.txt(位于others目录)的内容并测试之(也可在浏览器中访问相应的地址,如: http://localhost:8080/spring-oauth-server).
  • diff --git a/others/database/initial_data.ddl b/others/database/initial_data.ddl index 134aff6..66b6774 100644 --- a/others/database/initial_data.ddl +++ b/others/database/initial_data.ddl @@ -36,7 +36,7 @@ web_server_redirect_uri,authorities, access_token_validity, refresh_token_validity, additional_information, create_time, archived, trusted) values ('unity-client','sos-resource', '$2a$10$QQTKDdNfj9sPjak6c8oWaumvTsa10MxOBOV6BW3DvLWU6VrjDfDam', 'read','authorization_code,refresh_token,implicit', -'http://localhost:8080/spring-oauth-server/unity/dashboard','ROLE_CLIENT',null, +'http://localhost:8080/unity/dashboard','ROLE_CLIENT',null, null,null, now(), 0, 0), ('mobile-client','sos-resource', '$2a$10$uLvpxfvm3CuUyjIvYq7a9OUmd9b3tHFKrUaMyU/jC01thrTdkBDVm', 'read','password,refresh_token', null,'ROLE_CLIENT',null, diff --git a/others/oauth_test.txt b/others/oauth_test.txt index 98d345d..4f397d9 100644 --- a/others/oauth_test.txt +++ b/others/oauth_test.txt @@ -1,26 +1,27 @@ +最后更新:2021-11-20 方式1:基于浏览器 (访问时后跳到登录页面,登录成功后跳转到redirect_uri指定的地址) [GET] 说明:只能使用admin或unity 账号登录才能有权限访问,若使用mobile账号登录将返回Access is denied -http://localhost:8080/spring-oauth-server/oauth/authorize?client_id=unity-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard&response_type=code&scope=read +http://localhost:8080/oauth/authorize?client_id=unity-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2funity%2fdashboard&response_type=code&scope=read 说明: 由于mobile-client只支持password,refresh_token, 所以不管用哪个账号登录后都将返回 OAuth Error -http://localhost:8080/spring-oauth-server/oauth/authorize?client_id=mobile-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2fm%2fdashboard&response_type=code&scope=read +http://localhost:8080/oauth/authorize?client_id=mobile-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fm%2fdashboard&response_type=code&scope=read 响应的URL如: -http://localhost:8080/spring-oauth-server/unity/dashboard?code=hGQ8qx +http://localhost:8080/unity/dashboard?code=hGQ8qx 通过code换取access_token [POST] (注意:这一步用httpclient在程序中调用,不要在浏览器中) -http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=authorization_code&code=hGQ8qx&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard +http://localhost:8080/oauth/token?client_id=unity-client&client_secret=unity&grant_type=authorization_code&code=hGQ8qx&redirect_uri=http%3a%2f%2flocalhost%3a8080%2funity%2fdashboard 方式2:基于客户端 (注意参数中的username,password,对应用户的账号,密码) [POST] (注意:这一步用httpclient在程序中调用,不要在浏览器中) -http://localhost:8080/spring-oauth-server/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=password&scope=read&username=mobile&password=mobile +http://localhost:8080/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=password&scope=read&username=mobile&password=mobile 说明:由于unity-client不支持password,所以若用unity-client通过password方式去授权,将返回 invalid_client -http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=password&scope=read&username=mobile&password=mobile +http://localhost:8080/oauth/token?client_id=unity-client&client_secret=unity&grant_type=password&scope=read&username=mobile&password=mobile @@ -29,19 +30,19 @@ http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&cli 获取access_token后访问资源 [GET] -http://localhost:8080/spring-oauth-server/unity/dashboard?access_token=89767569-5b78-4b26-ae2d-d361aa3e6bf9 +http://localhost:8080/unity/dashboard?access_token=89767569-5b78-4b26-ae2d-d361aa3e6bf9 刷新access_token [POST] (注意:这一步用httpclient在程序中调用,不要在浏览器中) -http://localhost:8080/spring-oauth-server/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=refresh_token&refresh_token=b36f4978-a172-4aa8-af89-60f58abe3ba1 +http://localhost:8080/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=refresh_token&refresh_token=b36f4978-a172-4aa8-af89-60f58abe3ba1 Restful OAuth2 Test [POST] (注意:这一步用httpclient在程序中调用,不要在浏览器中) URL: /oauth/rest_token ContentType: application/json -DEMO URL: http://localhost:8080/spring-oauth-server/oauth2/rest_token +DEMO URL: http://localhost:8080/oauth2/rest_token Request Body: {"grant_type":"client_credentials","scope":"read","client_id":"credentials","client_secret":"credentials","username":"user","password":"123"} @@ -82,12 +83,12 @@ Use it get resource-server resources after auth successful. will use it in