mirror of
https://github.com/usememos/memos.git
synced 2026-11-23 20:39:14 +01:00
23 lines
639 B
Go
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
|
|
}
|