# oauth-demo **Repository Path**: yangxsa/oauth-demo ## Basic Information - **Project Name**: oauth-demo - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-11 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 项目相关(单独的认证服务) spring boot + oauth2.0 + jwt 数据库管理资源服务的信息(数据库脚本在docs目录里面) redis 负责存储验证码的一些信息 简单的一个架子 ,,, 实现了基本的4个模式 和 自定义的手机验证码模式 (借鉴了其他项目 感谢大佬) 资源服务:https://gitee.com/yangxsa/resource-demo ## Oauth2提供的默认端点(endpoints) - /oauth/authorize:授权端点 - /oauth/token:令牌端点 - /oauth/confirm_access:用户确认授权提交端点 - /oauth/error:授权服务错误信息端点 - /oauth/check_token:用于资源服务访问的令牌解析端点(其他端检查token是否有效,会通过此接口验证) - /oauth/token_key:提供公有密匙的端点,如果使用JWT令牌的话(其他端检查token是否有效,会通过此接口验证) 以上端点都在认证服务端 # 密码模式 请求方式:POST 请求头:Authorization:Basic bW9iaWxlLWNsaWVudDptb2JpbGU= mobile-client mobile http://localhost:8001/oauth/token?grant_type=password&username=admin&password=123456 返回数据: { "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsic29zLXJlc291cmNlIl0sImV4cCI6MTU5OTU0MjkyMCwidXNlcl9uYW1lIjoiYWRtaW4iLCJqdGkiOiI3ZWQwNjg5Yy1hZDQ0LTRhZWMtYTQxMy02NTk5NDY0MWQzNGIiLCJjbGllbnRfaWQiOiJtb2JpbGUtY2xpZW50Iiwic2NvcGUiOlsicmVhZCJdfQ.uQ2W0aYejUozeYdrH9kTdwakdHeY9D1bxeGUaFtDta0", "token_type": "bearer", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsic29zLXJlc291cmNlIl0sInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsicmVhZCJdLCJhdGkiOiI3ZWQwNjg5Yy1hZDQ0LTRhZWMtYTQxMy02NTk5NDY0MWQzNGIiLCJleHAiOjE2MDIxMjc3MjAsImp0aSI6ImM5YzA0NTBjLWMwMWItNDJmNy05NWI1LWFiYWYyNmZkMmQyMiIsImNsaWVudF9pZCI6Im1vYmlsZS1jbGllbnQifQ.GjXB4CH3fnG6b-fU4mNUUDuVW6C76RDET3r-w10q8pU", "expires_in": 7194, "scope": "read", "user":{ "id": "1", "username": "admin", "password": "$2a$10$EF/joe.nzl4Cp8IpjjQtXud3EWKtCPSf1eeo6oLADyQWyhg7iOICy", "sex": "1", "authorities": null, "enabled": true, "accountNonExpired": true, "accountNonLocked": true, "credentialsNonExpired": true } } # 刷新TOKEN 请求方式:POST http://localhost:8001/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=refresh_token&refresh_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsic29zLXJlc291cmNlIl0sInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsicmVhZCJdLCJhdGkiOiIyNmQ5ZTNjNy01OWJjLTRhYTAtYWIyZi03NDk5YTU4N2I3MGYiLCJleHAiOjE2MDIxMjc0OTcsImp0aSI6ImQxOGU3MDA2LWRjYWEtNGM4Ny1hNjU2LThhZTJhY2Q5M2NlYyIsImNsaWVudF9pZCI6Im1vYmlsZS1jbGllbnQifQ.FA6v1S1PSe0HLgTMwh5xGSGAc23ErtP_JTaEkpVhkPs 返回数据 { "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsic29zLXJlc291cmNlIl0sImV4cCI6MTU5OTU0Mjk4MCwidXNlcl9uYW1lIjoiYWRtaW4iLCJqdGkiOiI2ODhmZjM1NC0xZTg3LTRmZmYtODMxMi05YmJhZDIzMjk0ZWQiLCJjbGllbnRfaWQiOiJtb2JpbGUtY2xpZW50Iiwic2NvcGUiOlsicmVhZCJdfQ.6fTBsLp7kLE4IiCYDnspti-vdgflCfNZS7HJN1W2H9A", "token_type": "bearer", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsic29zLXJlc291cmNlIl0sInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsicmVhZCJdLCJhdGkiOiI2ODhmZjM1NC0xZTg3LTRmZmYtODMxMi05YmJhZDIzMjk0ZWQiLCJleHAiOjE2MDIxMjc3MjAsImp0aSI6ImM5YzA0NTBjLWMwMWItNDJmNy05NWI1LWFiYWYyNmZkMmQyMiIsImNsaWVudF9pZCI6Im1vYmlsZS1jbGllbnQifQ.nNJnGOTmits6AjfK2e7OeOLe9JlsuqxNbIcVHitH_wE", "expires_in": 7198, "scope": "read" } # 简化模式 http://localhost:8001/oauth/authorize?client_id=unity-client&redirect_uri=http://localhost:8080/spring-oauth-server/unity/dashboard&response_type=token&scope=read //跳出登录页面,登录后 授权通过后返回token //由回调路径与token信息组成 http://localhost:8080/spring-oauth-server/unity/dashboard#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsic29zLXJlc291cmNlMiJdLCJleHAiOjE1OTk1NTE2MDksInVzZXJfbmFtZSI6ImFkbWluIiwianRpIjoiYWJhNmRlMWYtN2FlYS00NzhmLTg5ZDYtYzI4N2JhODE0N2U0IiwiY2xpZW50X2lkIjoidW5pdHktY2xpZW50Iiwic2NvcGUiOlsicmVhZCJdfQ._HHRO4FeLc74vG2wsHKHRUpfxtu0rADC8cVpI8VIYQc&token_type=bearer&expires_in=7199 #授权码模式 http://localhost:8001/oauth/authorize?client_id=unity-client&redirect_uri=http://localhost:8080/spring-oauth-server/unity/dashboard&response_type=code&scope=read&state=xyz //跳出登录页面,登录后 授权通过后返回code http://localhost:8080/spring-oauth-server/unity/dashboard?code=1cAls7&state=xyz 请求方法:POST //通过code返回token //请求头:Authorization:Basic dW5pdHktY2xpZW50OnVuaXR5 unity-client unity http://localhost:8001/oauth/token?grant_type=authorization_code&code=1cAls7&redirect_uri=http://localhost:8080/spring-oauth-server/unity/dashboard 返回内容 { "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsic29zLXJlc291cmNlMiJdLCJleHAiOjE1OTk1NTIwODcsInVzZXJfbmFtZSI6ImFkbWluIiwianRpIjoiZjcxMGIyMmMtOTg3Yi00NGE3LTk0NmYtODkzMzUxODFhNzg2IiwiY2xpZW50X2lkIjoidW5pdHktY2xpZW50Iiwic2NvcGUiOlsicmVhZCJdfQ.CLdrDATr8fL2uyfcdMRqzv5nR7OOt8K3LR5TGxIt2O8", "token_type": "bearer", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsic29zLXJlc291cmNlMiJdLCJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbInJlYWQiXSwiYXRpIjoiZjcxMGIyMmMtOTg3Yi00NGE3LTk0NmYtODkzMzUxODFhNzg2IiwiZXhwIjoxNjAyMTM2ODg3LCJqdGkiOiI2NThiNGJjZi1jZWM1LTQ2Y2MtYTU5Yi0zYTYyNDI2YTVjMDUiLCJjbGllbnRfaWQiOiJ1bml0eS1jbGllbnQifQ._O16zJji79lgfhd_eRmEg4MTA3aRof5OrWmSLcl7yFA", "expires_in": 7199, "scope": "read" } # 客户端模式 1、授权码模式:第三方Web服务器端应用与第三方原生App 2、简化模式:第三方单页面应用 3、密码模式:第一方单页应用与第一方原生App 4、客户端模式:没有用户参与的,完全信任的服务器端服务 请求方法: POST http://localhost:8001/oauth/token?grant_type=client_credentials&scope=read&client_id=unity-client&client_secret=unity # 自定义模式 - 手机验证码 头信息:Authorization:Basic cGN3ZWI6bW9iaWxl 明文 pcweb mobile http://localhost:8001/oauth/token?grant_type=mobile&code=1111&mobile=15908401995