1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user