1- import { type ClientRegistrationResponse } from "../oauth/types" ;
1+ import {
2+ type TokenResponse ,
3+ type ClientRegistrationResponse ,
4+ } from "../oauth/types" ;
25
36import type { SecretStorage , Disposable } from "vscode" ;
47
@@ -8,6 +11,12 @@ const LOGIN_STATE_KEY = "loginState";
811
912const OAUTH_CLIENT_REGISTRATION_KEY = "oauthClientRegistration" ;
1013
14+ const OAUTH_TOKENS_KEY = "oauthTokens" ;
15+
16+ export type StoredOAuthTokens = Omit < TokenResponse , "expires_in" > & {
17+ expiry_timestamp : number ;
18+ } ;
19+
1120export enum AuthAction {
1221 LOGIN ,
1322 LOGOUT ,
@@ -109,4 +118,39 @@ export class SecretsManager {
109118 }
110119 return undefined ;
111120 }
121+
122+ /**
123+ * Store OAuth token data including expiry timestamp.
124+ */
125+ public async setOAuthTokens (
126+ tokens : StoredOAuthTokens | undefined ,
127+ ) : Promise < void > {
128+ if ( tokens ) {
129+ await this . secrets . store ( OAUTH_TOKENS_KEY , JSON . stringify ( tokens ) ) ;
130+ } else {
131+ await this . secrets . delete ( OAUTH_TOKENS_KEY ) ;
132+ }
133+ }
134+
135+ /**
136+ * Get stored OAuth token data.
137+ */
138+ public async getOAuthTokens ( ) : Promise < StoredOAuthTokens | undefined > {
139+ try {
140+ const stringifiedTokens = await this . secrets . get ( OAUTH_TOKENS_KEY ) ;
141+ if ( stringifiedTokens ) {
142+ return JSON . parse ( stringifiedTokens ) as StoredOAuthTokens ;
143+ }
144+ } catch {
145+ // Do nothing
146+ }
147+ return undefined ;
148+ }
149+
150+ /**
151+ * Clear OAuth token data.
152+ */
153+ public async clearOAuthTokens ( ) : Promise < void > {
154+ await this . secrets . delete ( OAUTH_TOKENS_KEY ) ;
155+ }
112156}
0 commit comments