MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetOAuth2Client

Method GetOAuth2Client

backend/store/oauth2_client.go:58–87  ·  view source on GitHub ↗

GetOAuth2Client looks up a client by client_id (the table's primary key). Workspace is no longer a lookup key — clients are workspace-agnostic since DCR runs unauthenticated.

(ctx context.Context, clientID string)

Source from the content-addressed store, hash-verified

56// Workspace is no longer a lookup key — clients are workspace-agnostic since
57// DCR runs unauthenticated.
58func (s *Store) GetOAuth2Client(ctx context.Context, clientID string) (*OAuth2ClientMessage, error) {
59 q := qb.Q().Space(`
60 SELECT client_id, workspace, client_secret_hash, config, last_active_at
61 FROM oauth2_client
62 WHERE client_id = ?
63 `, clientID)
64
65 query, args, err := q.ToSQL()
66 if err != nil {
67 return nil, err
68 }
69
70 client := &OAuth2ClientMessage{}
71 var workspace sql.NullString
72 var configBytes []byte
73 if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan( // NOSONAR: query is parameterized via qb.Query
74 &client.ClientID, &workspace, &client.ClientSecretHash, &configBytes, &client.LastActiveAt,
75 ); err != nil {
76 if errors.Is(err, sql.ErrNoRows) {
77 return nil, nil
78 }
79 return nil, errors.Wrap(err, "failed to query OAuth2 client")
80 }
81 client.Workspace = workspace.String
82 client.Config = &storepb.OAuth2ClientConfig{}
83 if err := common.ProtojsonUnmarshaler.Unmarshal(configBytes, client.Config); err != nil {
84 return nil, errors.Wrap(err, "failed to unmarshal config")
85 }
86 return client, nil
87}
88
89func (s *Store) UpdateOAuth2ClientLastActiveAt(ctx context.Context, clientID string) error {
90 q := qb.Q().Space(`

Callers 5

handleRevokeMethod · 0.80
handleGetClientMethod · 0.80
handleAuthorizeGetMethod · 0.80
handleAuthorizePostMethod · 0.80
handleTokenMethod · 0.80

Calls 6

GetDBMethod · 0.95
QFunction · 0.92
SpaceMethod · 0.80
ToSQLMethod · 0.80
ScanMethod · 0.80
UnmarshalMethod · 0.80

Tested by

no test coverage detected