@@ -77,11 +77,19 @@ interface RevokeAccessTokenResponse {
77
77
revoked : boolean ;
78
78
}
79
79
80
+ interface TokenResponse {
81
+ refresh_token : string ;
82
+ access_token : string ;
83
+ token_type : string ;
84
+ expires_in : number ;
85
+ scope : string ;
86
+ }
87
+
80
88
/**
81
89
* Twitter OAuth2 Authentication Client
82
90
*/
83
91
export class OAuth2User implements AuthClient {
84
- # access_token?: string ;
92
+ access_token ?: string ;
85
93
token_type ?: string ;
86
94
expires_at ?: Date ;
87
95
scope ?: string ;
@@ -105,7 +113,7 @@ export class OAuth2User implements AuthClient {
105
113
if ( ! refresh_token ) {
106
114
throw new Error ( "refresh_token is required" ) ;
107
115
}
108
- const data = await rest ( {
116
+ const data = await rest < TokenResponse > ( {
109
117
...request_options ,
110
118
endpoint : `/2/oauth2/token` ,
111
119
params : {
@@ -128,9 +136,9 @@ export class OAuth2User implements AuthClient {
128
136
/**
129
137
* Update token information
130
138
*/
131
- updateToken ( data : Record < string , any > ) : void {
139
+ updateToken ( data : TokenResponse ) : void {
132
140
this . refresh_token = data . refresh_token ;
133
- this . # access_token = data . access_token ;
141
+ this . access_token = data . access_token ;
134
142
this . token_type = data . token_type ;
135
143
this . expires_at = new Date ( Date . now ( ) + data . expires_in * 1000 ) ;
136
144
this . scope = data . scope ;
@@ -168,7 +176,7 @@ export class OAuth2User implements AuthClient {
168
176
client_id,
169
177
redirect_uri : callback ,
170
178
} ;
171
- const data = await rest ( {
179
+ const data = await rest < TokenResponse > ( {
172
180
...request_options ,
173
181
endpoint : `/2/oauth2/token` ,
174
182
params,
@@ -189,7 +197,7 @@ export class OAuth2User implements AuthClient {
189
197
*/
190
198
async revokeAccessToken ( ) : Promise < RevokeAccessTokenResponse > {
191
199
const { client_id, client_secret, request_options } = this . #options;
192
- const access_token = this . # access_token;
200
+ const access_token = this . access_token ;
193
201
const refresh_token = this . refresh_token ;
194
202
if ( ! client_id ) {
195
203
throw new Error ( "client_id is required" ) ;
@@ -252,10 +260,10 @@ export class OAuth2User implements AuthClient {
252
260
}
253
261
254
262
async getAuthHeader ( ) : Promise < AuthHeader > {
255
- if ( ! this . # access_token) throw new Error ( "You do not have an access token " ) ;
263
+ if ( ! this . access_token ) throw new Error ( "access_token is required " ) ;
256
264
if ( this . isAccessTokenExpired ( ) ) await this . refreshAccessToken ( ) ;
257
265
return {
258
- Authorization : `Bearer ${ this . # access_token} ` ,
266
+ Authorization : `Bearer ${ this . access_token } ` ,
259
267
} ;
260
268
}
261
269
}
0 commit comments