1. system 提供 OAuth2TokenApi 接口

2. gateway 通过 feign 引入 OAuth2TokenApi 接口
This commit is contained in:
YunaiV
2022-06-03 01:11:13 +08:00
parent 94d62b8d79
commit e89ef5496c
7 changed files with 121 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
package cn.iocoder.yudao.gateway.util;
import org.springframework.util.StringUtils;
import org.springframework.web.server.ServerWebExchange;
/**
* 安全服务工具类
*
* copy from yudao-spring-boot-starter-security 的 SecurityFrameworkUtils 类
*
* @author 芋道源码
*/
public class SecurityFrameworkUtils {
public static final String AUTHORIZATION_HEADER = "Authorization";
public static final String AUTHORIZATION_BEARER = "Bearer";
private SecurityFrameworkUtils() {}
/**
* 从请求中,获得认证 Token
*
* @param exchange 请求
* @return 认证 Token
*/
public static String obtainAuthorization(ServerWebExchange exchange) {
String authorization = exchange.getRequest().getHeaders().getFirst(AUTHORIZATION_HEADER);
if (!StringUtils.hasText(authorization)) {
return null;
}
int index = authorization.indexOf(AUTHORIZATION_BEARER + " ");
if (index == -1) { // 未找到
return null;
}
return authorization.substring(index + 7).trim();
}
}