mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-22 18:25:47 +08:00
Refactor GenerateCasToken()
This commit is contained in:
parent
a9de7d3aef
commit
3c2fd574a6
@ -185,9 +185,14 @@ func StoreCasTokenForProxyTicket(token *CasAuthenticationSuccess, targetService,
|
||||
}
|
||||
|
||||
func GenerateCasToken(userId string, service string) (string, error) {
|
||||
if user, err := GetUser(userId); err != nil {
|
||||
user, err := GetUser(userId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else if user != nil {
|
||||
}
|
||||
if user == nil {
|
||||
return "", fmt.Errorf("The user: %s doesn't exist", userId)
|
||||
}
|
||||
|
||||
authenticationSuccess := CasAuthenticationSuccess{
|
||||
User: user.Name,
|
||||
Attributes: &CasAttributes{
|
||||
@ -196,9 +201,18 @@ func GenerateCasToken(userId string, service string) (string, error) {
|
||||
},
|
||||
ProxyGrantingTicket: fmt.Sprintf("PGTIOU-%s", util.GenerateId()),
|
||||
}
|
||||
data, _ := json.Marshal(user)
|
||||
|
||||
data, err := json.Marshal(user)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
tmp := map[string]string{}
|
||||
json.Unmarshal(data, &tmp)
|
||||
err = json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for k, v := range tmp {
|
||||
if v != "" {
|
||||
authenticationSuccess.Attributes.UserAttributes.Attributes = append(authenticationSuccess.Attributes.UserAttributes.Attributes, &CasNamedAttribute{
|
||||
@ -207,6 +221,7 @@ func GenerateCasToken(userId string, service string) (string, error) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
st := fmt.Sprintf("ST-%d", rand.Int())
|
||||
stToServiceResponse.Store(st, &CasAuthenticationSuccessWrapper{
|
||||
AuthenticationSuccess: &authenticationSuccess,
|
||||
@ -214,9 +229,6 @@ func GenerateCasToken(userId string, service string) (string, error) {
|
||||
UserId: userId,
|
||||
})
|
||||
return st, nil
|
||||
} else {
|
||||
return "", fmt.Errorf("invalid user Id")
|
||||
}
|
||||
}
|
||||
|
||||
// GetValidationBySaml
|
||||
|
Loading…
x
Reference in New Issue
Block a user