| 181 | } |
| 182 | |
| 183 | async request(authData, options) { |
| 184 | const { consumer_key, consumer_secret } = options; |
| 185 | |
| 186 | const oauth = { |
| 187 | consumer_key, |
| 188 | consumer_secret, |
| 189 | auth_token: authData.oauth_token, |
| 190 | auth_token_secret: authData.oauth_token_secret, |
| 191 | }; |
| 192 | |
| 193 | const url = new URL('https://api.twitter.com/2/users/me'); |
| 194 | |
| 195 | const response = await fetch(url, { |
| 196 | headers: { |
| 197 | Authorization: 'Bearer ' + oauth.auth_token, |
| 198 | }, |
| 199 | body: JSON.stringify(oauth), |
| 200 | }); |
| 201 | |
| 202 | if (!response.ok) { |
| 203 | throw new Error('Failed to fetch user data.'); |
| 204 | } |
| 205 | |
| 206 | return response; |
| 207 | } |
| 208 | |
| 209 | async beforeFind(authData) { |
| 210 | if (this.enableInsecureAuth && !authData?.code) { |