| 45 | } |
| 46 | |
| 47 | func (s *Store) GetOAuth2RefreshToken(ctx context.Context, clientID, tokenHash string) (*OAuth2RefreshTokenMessage, error) { |
| 48 | q := qb.Q().Space(` |
| 49 | SELECT token_hash, client_id, user_email, workspace, expires_at |
| 50 | FROM oauth2_refresh_token |
| 51 | WHERE token_hash = ? AND client_id = ? |
| 52 | `, tokenHash, clientID) |
| 53 | |
| 54 | query, args, err := q.ToSQL() |
| 55 | if err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | msg := &OAuth2RefreshTokenMessage{} |
| 60 | var workspace sql.NullString |
| 61 | if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan( |
| 62 | &msg.TokenHash, &msg.ClientID, &msg.UserEmail, &workspace, &msg.ExpiresAt, |
| 63 | ); err != nil { |
| 64 | if errors.Is(err, sql.ErrNoRows) { |
| 65 | return nil, nil |
| 66 | } |
| 67 | return nil, errors.Wrap(err, "failed to get OAuth2 refresh token") |
| 68 | } |
| 69 | msg.Workspace = workspace.String |
| 70 | return msg, nil |
| 71 | } |
| 72 | |
| 73 | func (s *Store) DeleteOAuth2RefreshToken(ctx context.Context, clientID, tokenHash string) error { |
| 74 | q := qb.Q().Space(` |