Files
memos/server/api/sso_username.go
T

23 lines
639 B
Go

package api
import (
"github.com/pkg/errors"
"github.com/usememos/memos/internal/random"
)
const ssoUsernameFallbackAttempts = 5
// deriveSSOUsername produces the local username for a new SSO-created user.
//
// UUID usernames are the fallback when the IdP identifier cannot safely be used
// as the local username, such as when it is invalid or already belongs to
// another local account.
func deriveSSOUsername() (string, error) {
username := random.UUID()
if err := validateWritableUsername(username); err != nil {
return "", errors.Wrap(err, "generated UUID did not satisfy username constraints")
}
return username, nil
}