2022-07-06 01:22:57 +00:00
|
|
|
package oauth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-06-18 18:59:12 +00:00
|
|
|
"strconv"
|
2022-07-06 01:22:57 +00:00
|
|
|
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
|
|
)
|
|
|
|
|
2024-06-28 17:59:28 +00:00
|
|
|
func getUsername(datamap map[string]any, configuration *portainer.OAuthSettings) (string, error) {
|
2022-07-06 01:22:57 +00:00
|
|
|
username, ok := datamap[configuration.UserIdentifier].(string)
|
|
|
|
if ok && username != "" {
|
|
|
|
return username, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
username, ok := datamap[configuration.UserIdentifier].(float64)
|
|
|
|
if ok && username != 0 {
|
2024-06-18 18:59:12 +00:00
|
|
|
return strconv.Itoa(int(username)), nil
|
2022-07-06 01:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", errors.New("failed to extract username from oauth resource")
|
|
|
|
}
|