新增 hideStatusField 配置项,用于指定是否在返回值中隐藏默认的状态字段 (code、msg、data)

This commit is contained in:
click33
2024-08-24 04:44:14 +08:00
parent 760805f78c
commit 8c008a1aec
3 changed files with 35 additions and 6 deletions

View File

@@ -75,6 +75,10 @@ public class SaOAuth2ServerConfig implements Serializable {
/** 模式4是否返回 AccessToken 字段 */
public Boolean mode4ReturnAccessToken = false;
/** 是否在返回值中隐藏默认的状态字段 (code、msg、data) */
public Boolean hideStatusField = false;
/**
* oidc 相关配置
*/
@@ -310,6 +314,21 @@ public class SaOAuth2ServerConfig implements Serializable {
return this;
}
/**
* @return hideStatusField
*/
public Boolean getHideStatusField() {
return hideStatusField;
}
/**
* @param hideStatusField 要设置的 hideStatusField
*/
public SaOAuth2ServerConfig setHideStatusField(Boolean hideStatusField) {
this.hideStatusField = hideStatusField;
return this;
}
/**
* 获取 oidc 相关配置
*
@@ -365,6 +384,7 @@ public class SaOAuth2ServerConfig implements Serializable {
", higherScope='" + higherScope +
", lowerScope='" + lowerScope +
", mode4ReturnAccessToken='" + mode4ReturnAccessToken +
", hideStatusField='" + hideStatusField +
", oidc='" + oidc +
'}';
}

View File

@@ -130,11 +130,15 @@ public class SaOAuth2DataResolverDefaultImpl implements SaOAuth2DataResolver {
map.put("client_id", at.clientId);
map.put("scope", SaOAuth2Manager.getDataConverter().convertScopeListToString(at.scopes));
map.putAll(at.extraData);
return SaResult.ok().setMap(map);
SaResult result = SaResult.ok().setMap(map);
if(SaOAuth2Manager.getServerConfig().hideStatusField) {
result.removeDefaultFields();
}
return result;
}
/**
* 构建返回值: password 模式认证 获取 token
* 构建返回值: 凭证式 模式认证 获取 token
*/
@Override
public Map<String, Object> buildClientTokenReturnValue(ClientTokenModel ct) {
@@ -149,7 +153,12 @@ public class SaOAuth2DataResolverDefaultImpl implements SaOAuth2DataResolver {
map.put("client_id", ct.clientId);
map.put("scope", SaOAuth2Manager.getDataConverter().convertScopeListToString(ct.scopes));
map.putAll(ct.extraData);
return SaResult.ok().setMap(map);
SaResult result = SaResult.ok().setMap(map);
if(SaOAuth2Manager.getServerConfig().hideStatusField) {
result.removeDefaultFields();
}
return result;
}
}