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,38 +185,50 @@ func StoreCasTokenForProxyTicket(token *CasAuthenticationSuccess, targetService,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GenerateCasToken(userId string, service string) (string, error) {
|
func GenerateCasToken(userId string, service string) (string, error) {
|
||||||
if user, err := GetUser(userId); err != nil {
|
user, err := GetUser(userId)
|
||||||
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
} else if user != nil {
|
|
||||||
authenticationSuccess := CasAuthenticationSuccess{
|
|
||||||
User: user.Name,
|
|
||||||
Attributes: &CasAttributes{
|
|
||||||
AuthenticationDate: time.Now(),
|
|
||||||
UserAttributes: &CasUserAttributes{},
|
|
||||||
},
|
|
||||||
ProxyGrantingTicket: fmt.Sprintf("PGTIOU-%s", util.GenerateId()),
|
|
||||||
}
|
|
||||||
data, _ := json.Marshal(user)
|
|
||||||
tmp := map[string]string{}
|
|
||||||
json.Unmarshal(data, &tmp)
|
|
||||||
for k, v := range tmp {
|
|
||||||
if v != "" {
|
|
||||||
authenticationSuccess.Attributes.UserAttributes.Attributes = append(authenticationSuccess.Attributes.UserAttributes.Attributes, &CasNamedAttribute{
|
|
||||||
Name: k,
|
|
||||||
Value: v,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
st := fmt.Sprintf("ST-%d", rand.Int())
|
|
||||||
stToServiceResponse.Store(st, &CasAuthenticationSuccessWrapper{
|
|
||||||
AuthenticationSuccess: &authenticationSuccess,
|
|
||||||
Service: service,
|
|
||||||
UserId: userId,
|
|
||||||
})
|
|
||||||
return st, nil
|
|
||||||
} else {
|
|
||||||
return "", fmt.Errorf("invalid user Id")
|
|
||||||
}
|
}
|
||||||
|
if user == nil {
|
||||||
|
return "", fmt.Errorf("The user: %s doesn't exist", userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticationSuccess := CasAuthenticationSuccess{
|
||||||
|
User: user.Name,
|
||||||
|
Attributes: &CasAttributes{
|
||||||
|
AuthenticationDate: time.Now(),
|
||||||
|
UserAttributes: &CasUserAttributes{},
|
||||||
|
},
|
||||||
|
ProxyGrantingTicket: fmt.Sprintf("PGTIOU-%s", util.GenerateId()),
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := json.Marshal(user)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp := map[string]string{}
|
||||||
|
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{
|
||||||
|
Name: k,
|
||||||
|
Value: v,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
st := fmt.Sprintf("ST-%d", rand.Int())
|
||||||
|
stToServiceResponse.Store(st, &CasAuthenticationSuccessWrapper{
|
||||||
|
AuthenticationSuccess: &authenticationSuccess,
|
||||||
|
Service: service,
|
||||||
|
UserId: userId,
|
||||||
|
})
|
||||||
|
return st, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetValidationBySaml
|
// GetValidationBySaml
|
||||||
|
Loading…
x
Reference in New Issue
Block a user