Compare commits

...

2 Commits

Author SHA1 Message Date
DacongDA
bc94735a8d feat: add the username parameter in SAML or OAuth2 (#4161) 2025-09-06 22:03:18 +08:00
DacongDA
89c6ef5aae feat: support "permissionNames" field in JWT-Custom token (#4154) 2025-09-06 00:05:47 +08:00
3 changed files with 10 additions and 2 deletions

View File

@@ -370,6 +370,12 @@ func getClaimsCustom(claims Claims, tokenField []string) jwt.MapClaims {
res[fieldName] = finalField.Interface()
}
} else if field == "permissionNames" {
permissionNames := []string{}
for _, val := range claims.User.Permissions {
permissionNames = append(permissionNames, val.Name)
}
res[util.SnakeToCamel(util.CamelToSnakeCase(field))] = permissionNames
} else { // Use selected user field as claims.
userField := userValue.FieldByName(field)
if userField.IsValid() {

View File

@@ -463,7 +463,7 @@ class ApplicationEditPage extends React.Component {
<Select virtual={false} disabled={this.state.application.tokenFormat !== "JWT-Custom"} mode="tags" showSearch style={{width: "100%"}} value={this.state.application.tokenFields} onChange={(value => {this.updateApplicationField("tokenFields", value);})}>
<Option key={"provider"} value={"provider"}>{"Provider"}</Option>)
{
Setting.getUserCommonFields().map((item, index) => <Option key={index} value={item}>{item}</Option>)
[...Setting.getUserCommonFields(), "permissionNames"].map((item, index) => <Option key={index} value={item}>{item}</Option>)
}
</Select>
</Col>

View File

@@ -47,6 +47,7 @@ class LoginPage extends React.Component {
constructor(props) {
super(props);
this.captchaRef = React.createRef();
const urlParams = new URLSearchParams(this.props.location?.search);
this.state = {
classes: props,
type: props.type,
@@ -70,6 +71,7 @@ class LoginPage extends React.Component {
loginLoading: false,
userCode: props.userCode ?? (props.match?.params?.userCode ?? null),
userCodeStatus: "",
prefilledUsername: urlParams.get("username") || urlParams.get("login_hint"),
};
if (this.state.type === "cas" && props.match?.params.casApplicationName !== undefined) {
@@ -1011,7 +1013,7 @@ class LoginPage extends React.Component {
organization: application.organization,
application: application.name,
autoSignin: !application?.signinItems.map(signinItem => signinItem.name === "Forgot password?" && signinItem.rule === "Auto sign in - False")?.includes(true),
username: Conf.ShowGithubCorner ? "admin" : "",
username: this.state.prefilledUsername || (Conf.ShowGithubCorner ? "admin" : ""),
password: Conf.ShowGithubCorner ? "123" : "",
}}
onFinish={(values) => {