v2: fixed oauth errors, oauth clients native control added
This commit is contained in:
@@ -63,6 +63,77 @@ func (r *OAuthRepository) GetOAuthClientByID(ctx context.Context, id uuid.UUID)
|
||||
return &client, nil
|
||||
}
|
||||
|
||||
func (r *OAuthRepository) ListOAuthClients(ctx context.Context) ([]models.OAuthClient, error) {
|
||||
rows, err := r.db.Query(ctx, `
|
||||
SELECT id, client_id, client_secret, name, redirect_uris, grant_types, scopes, is_active, trusted, created_at, updated_at
|
||||
FROM oauth_clients
|
||||
ORDER BY created_at DESC
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var clients []models.OAuthClient
|
||||
for rows.Next() {
|
||||
var c models.OAuthClient
|
||||
if err := rows.Scan(
|
||||
&c.ID, &c.ClientID, &c.ClientSecret, &c.Name,
|
||||
&c.RedirectURIs, &c.GrantTypes, &c.Scopes,
|
||||
&c.IsActive, &c.Trusted, &c.CreatedAt, &c.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clients = append(clients, c)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return clients, nil
|
||||
}
|
||||
|
||||
func (r *OAuthRepository) GetOAuthClientByIDAdmin(ctx context.Context, id uuid.UUID) (*models.OAuthClient, error) {
|
||||
var client models.OAuthClient
|
||||
err := r.db.QueryRow(ctx, `
|
||||
SELECT id, client_id, client_secret, name, redirect_uris, grant_types, scopes, is_active, trusted, created_at, updated_at
|
||||
FROM oauth_clients WHERE id = $1
|
||||
`, id).Scan(
|
||||
&client.ID, &client.ClientID, &client.ClientSecret, &client.Name,
|
||||
&client.RedirectURIs, &client.GrantTypes, &client.Scopes,
|
||||
&client.IsActive, &client.Trusted, &client.CreatedAt, &client.UpdatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &client, nil
|
||||
}
|
||||
|
||||
func (r *OAuthRepository) UpdateOAuthClient(ctx context.Context, client models.OAuthClient) (*models.OAuthClient, error) {
|
||||
err := r.db.QueryRow(ctx, `
|
||||
UPDATE oauth_clients
|
||||
SET name = $1,
|
||||
redirect_uris = $2,
|
||||
grant_types = $3,
|
||||
scopes = $4,
|
||||
trusted = $5,
|
||||
is_active = $6,
|
||||
updated_at = now()
|
||||
WHERE id = $7
|
||||
RETURNING updated_at
|
||||
`, client.Name, client.RedirectURIs, client.GrantTypes, client.Scopes,
|
||||
client.Trusted, client.IsActive, client.ID).
|
||||
Scan(&client.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("update oauth client: %w", err)
|
||||
}
|
||||
return &client, nil
|
||||
}
|
||||
|
||||
func (r *OAuthRepository) DeactivateOAuthClient(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := r.db.Exec(ctx, `UPDATE oauth_clients SET is_active = false, updated_at = now() WHERE id = $1`, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *OAuthRepository) CreateAuthorizationCode(ctx context.Context, row models.AuthorizationCodeRow) (*models.AuthorizationCodeRow, error) {
|
||||
err := r.db.QueryRow(ctx, `
|
||||
INSERT INTO authorization_codes (code_hash, user_id, client_id, redirect_uri, scopes, code_challenge, code_challenge_method, expires_at, consumed_at, created_at)
|
||||
|
||||
Reference in New Issue
Block a user