Skip to content

Commit d2b3282

Browse files
authored
fix: Add support for auto-registering clients (#26)
1 parent 047a7e8 commit d2b3282

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

server.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,33 @@ func (s *Server) GetIdentity(ctx context.Context, id, accountID, projectID strin
441441
return s.identitySvc.GetIdentity(ctx, id, accountID, projectID)
442442
}
443443

444+
// PublicClientConfig defines a public OAuth client to ensure on startup.
445+
type PublicClientConfig struct {
446+
ClientID string
447+
Name string
448+
AccountID string
449+
ProjectID string
450+
GrantTypes []string
451+
Scopes []string
452+
RedirectURIs []string
453+
}
454+
455+
// EnsurePublicClient registers a public PKCE OAuth client if it doesn't already exist.
456+
// Idempotent — safe to call on every startup.
457+
func (s *Server) EnsurePublicClient(ctx context.Context, cfg PublicClientConfig) error {
458+
_, err := s.oauthClientSvc.GetPublicClient(ctx, cfg.ClientID, cfg.AccountID, cfg.ProjectID)
459+
if err == nil {
460+
return nil // already exists
461+
}
462+
463+
_, regErr := s.oauthClientSvc.RegisterPublicClient(
464+
ctx, cfg.AccountID, cfg.ProjectID, cfg.Name, cfg.ClientID,
465+
cfg.RedirectURIs, cfg.GrantTypes, cfg.Scopes,
466+
)
467+
468+
return regErr
469+
}
470+
444471
// ──────────────────────────────────────────────────────────────────────────────
445472
// Internal helpers
446473
// ──────────────────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)