This commit is contained in:
Leo
2026-01-15 20:38:45 +08:00
parent 7f7bec8d29
commit a41c9ceaf9
4 changed files with 64 additions and 6 deletions

View File

@@ -41,6 +41,9 @@ public class WPS365Config {
/** 刷新Token地址 */
private String refreshTokenUrl = "https://openapi.wps.cn/oauth2/token";
/** OAuth授权请求的scope权限可选如果不配置则使用默认值 */
private String scope;
/**
* 配置初始化后验证
*/
@@ -117,5 +120,13 @@ public class WPS365Config {
public void setRefreshTokenUrl(String refreshTokenUrl) {
this.refreshTokenUrl = refreshTokenUrl;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}

View File

@@ -92,9 +92,29 @@ public class WPS365OAuthServiceImpl implements IWPS365OAuthService {
log.debug("授权URL参数 - response_type: code");
// scope参数必需根据WPS365文档
String scope = "file.read,ksheet.read,user.info";
authUrl.append("&scope=").append(scope);
log.debug("授权URL参数 - scope: {}", scope);
// 优先使用配置文件中指定的scope如果没有配置则使用默认值
// 注意WPS365的scope格式可能是空格分隔而不是逗号分隔
String scope = wps365Config.getScope();
if (scope == null || scope.trim().isEmpty()) {
// 默认scope如果报错invalid_scope请检查WPS365平台支持的scope格式
// 常见格式:
// 1. 逗号分隔file.read,ksheet.read,user.info
// 2. 空格分隔file.read ksheet.read user.info
// 3. 冒号格式file:read ksheet:read user:info
// 请根据WPS365平台后台显示的scope格式进行配置
scope = "file.read ksheet.read user.info"; // 尝试空格分隔
}
scope = scope.trim();
// URL编码scope参数
try {
String encodedScope = java.net.URLEncoder.encode(scope, "UTF-8");
authUrl.append("&scope=").append(encodedScope);
log.debug("授权URL参数 - scope: {} (编码后: {})", scope, encodedScope);
} catch (java.io.UnsupportedEncodingException e) {
log.error("Scope URL编码失败", e);
authUrl.append("&scope=").append(scope);
}
// state参数推荐用于防止CSRF攻击
if (state == null || state.trim().isEmpty()) {