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
|
|
|
)
|
|
|
|
|
2024-10-28 20:28:22 +00:00
|
|
|
func GetUsername(datamap map[string]any, userIdentifier string) (string, error) {
|
|
|
|
username, ok := datamap[userIdentifier].(string)
|
2022-07-06 01:22:57 +00:00
|
|
|
if ok && username != "" {
|
|
|
|
return username, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
2024-10-28 20:28:22 +00:00
|
|
|
username, ok := datamap[userIdentifier].(float64)
|
2022-07-06 01:22:57 +00:00
|
|
|
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")
|
|
|
|
}
|