细节优化、文档优化
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ public class SaOAuth2ServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SaOAuth2ServerApplication.class, args);
|
||||
System.out.println("\nSa-Token-OAuth Server端启动成功,配置如下:");
|
||||
System.out.println("\nSa-Token-OAuth2 Server端启动成功,配置如下:");
|
||||
System.out.println(SaOAuth2Manager.getConfig());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ public class SaOAuth2DataLoaderImpl implements SaOAuth2DataLoader {
|
||||
return new SaClientModel()
|
||||
.setClientId("1001") // client id
|
||||
.setClientSecret("aaaa-bbbb-cccc-dddd-eeee") // client 秘钥
|
||||
.addAllowUrls("*") // 所有允许授权的 url
|
||||
.addAllowRedirectUris("*") // 所有允许授权的 url
|
||||
.addContractScopes("openid", "userid", "userinfo") // 所有签约的权限
|
||||
.addAllowGrantTypes( // 所有允许的授权模式
|
||||
GrantType.authorization_code, // 授权码式
|
||||
|
||||
+8
-7
@@ -1,7 +1,7 @@
|
||||
package com.pj.oauth2;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.oauth2.config.SaOAuth2Config;
|
||||
import cn.dev33.satoken.oauth2.config.SaOAuth2ServerConfig;
|
||||
import cn.dev33.satoken.oauth2.processor.SaOAuth2ServerProcessor;
|
||||
import cn.dev33.satoken.oauth2.template.SaOAuth2Util;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
@@ -24,23 +24,23 @@ import java.util.Map;
|
||||
@RestController
|
||||
public class SaOAuth2ServerController {
|
||||
|
||||
// OAuth2-Server 端:处理所有OAuth相关请求
|
||||
// OAuth2-Server 端:处理所有 OAuth2 相关请求
|
||||
@RequestMapping("/oauth2/*")
|
||||
public Object request() {
|
||||
System.out.println("------- 进入请求: " + SaHolder.getRequest().getUrl());
|
||||
return SaOAuth2ServerProcessor.instance.dister();
|
||||
}
|
||||
|
||||
// Sa-OAuth2 定制化配置
|
||||
// Sa-Token OAuth2 定制化配置
|
||||
@Autowired
|
||||
public void configOAuth2Server(SaOAuth2Config cfg) {
|
||||
public void configOAuth2Server(SaOAuth2ServerConfig oauth2Server) {
|
||||
// 未登录的视图
|
||||
cfg.notLoginView = ()->{
|
||||
oauth2Server.notLoginView = ()->{
|
||||
return new ModelAndView("login.html");
|
||||
};
|
||||
|
||||
// 登录处理函数
|
||||
cfg.doLoginHandle = (name, pwd) -> {
|
||||
oauth2Server.doLoginHandle = (name, pwd) -> {
|
||||
if("sa".equals(name) && "123456".equals(pwd)) {
|
||||
StpUtil.login(10001);
|
||||
return SaResult.ok();
|
||||
@@ -49,12 +49,13 @@ public class SaOAuth2ServerController {
|
||||
};
|
||||
|
||||
// 授权确认视图
|
||||
cfg.confirmView = (clientId, scopes)->{
|
||||
oauth2Server.confirmView = (clientId, scopes)->{
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("clientId", clientId);
|
||||
map.put("scope", scopes);
|
||||
return new ModelAndView("confirm.html", map);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -26,8 +26,9 @@ public class PhoneCodeGrantTypeHandler implements SaOAuth2GrantTypeHandlerInterf
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessTokenModel getAccessTokenModel(SaRequest req, String clientId, List<String> scopes) {
|
||||
public AccessTokenModel getAccessToken(SaRequest req, String clientId, List<String> scopes) {
|
||||
|
||||
// 获取前端提交的参数
|
||||
String phone = req.getParamNotNull("phone");
|
||||
String code = req.getParamNotNull("code");
|
||||
String realCode = SaManager.getSaTokenDao().get("phone_code:" + phone);
|
||||
|
||||
+4
-4
@@ -4,19 +4,19 @@ server:
|
||||
# sa-token配置
|
||||
sa-token:
|
||||
# token名称 (同时也是 Cookie 名称)
|
||||
token-name: satoken-oauth2-server
|
||||
token-name: sa-token-oauth2-server
|
||||
# 是否打印操作日志
|
||||
is-log: true
|
||||
# OAuth2.0 配置
|
||||
oauth2:
|
||||
oauth2-server:
|
||||
# 是否全局开启授权码模式
|
||||
enable-code: true
|
||||
enable-authorization-code: true
|
||||
# 是否全局开启 Implicit 模式
|
||||
enable-implicit: true
|
||||
# 是否全局开启密码模式
|
||||
enable-password: true
|
||||
# 是否全局开启客户端模式
|
||||
enable-client: true
|
||||
enable-client-credentials: true
|
||||
# 定义哪些 scope 是高级权限,多个用逗号隔开
|
||||
# higher-scope: openid,userid
|
||||
# 定义哪些 scope 是低级权限,多个用逗号隔开
|
||||
|
||||
Reference in New Issue
Block a user