feat(auth): add additional OAuth endpoints and improve client ID handling
This commit is contained in:
@@ -2,7 +2,8 @@ package auth
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -42,21 +43,26 @@ func (s *DynamicClientStore) Register(name string, redirectURIs []string) (Dynam
|
||||
return DynamicClient{}, err
|
||||
}
|
||||
client := DynamicClient{
|
||||
ClientID: hex.EncodeToString(b),
|
||||
ClientID: fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]),
|
||||
ClientName: name,
|
||||
RedirectURIs: append([]string(nil), redirectURIs...),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.clients[client.ClientID] = client
|
||||
s.clients[normalizeClientID(client.ClientID)] = client
|
||||
s.mu.Unlock()
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// Lookup returns the client for the given client_id.
|
||||
// Accepts UUIDs with or without dashes.
|
||||
func (s *DynamicClientStore) Lookup(clientID string) (DynamicClient, bool) {
|
||||
s.mu.RLock()
|
||||
client, ok := s.clients[clientID]
|
||||
client, ok := s.clients[normalizeClientID(clientID)]
|
||||
s.mu.RUnlock()
|
||||
return client, ok
|
||||
}
|
||||
|
||||
func normalizeClientID(id string) string {
|
||||
return strings.ReplaceAll(id, "-", "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user