import { OAuth } from "oauth" ; import { InternalOptions } from "src/lib/types" ; /**
 * Client supporting OAuth 1.x
 */ export function oAuth1Client ( options ) { const provider = options . provider ; const oauth1Client = new OAuth ( provider . requestTokenUrl as string , provider . accessTokenUrl as string , provider . clientId as string , provider . clientSecret as string , provider . version ?? "1.0" , provider . callbackUrl , provider . encoding ?? "HMAC-SHA1" ) ; const originalGet = oauth1Client . get . bind ( oauth1Client ) ; oauth1Client . get = async ( ... args ) => { return await new Promise ( ( resolve , reject ) => { originalGet ( ... args , ( error , result ) => { if ( error ) { return reject ( error ) ; } resolve ( result ) ; } ) ; } ) ; } ; const originalGetOAuth1AccessToken = oauth1Client . getOAuthAccessToken . bind ( oauth1Client ) ; oauth1Client . getOAuthAccessToken = async ( ... args ) => { return await new Promise ( ( resolve , reject ) => { originalGetOAuth1AccessToken ( ... args , ( error , oauth_token , oauth_token_secret ) => { if ( error ) { return reject ( error ) ; } resolve ( { oauth_token , oauth_token_secret } as any ) ; } ) ; } ) ; } ; const originalGetOAuthRequestToken = oauth1Client . getOAuthRequestToken . bind ( oauth1Client ) ; oauth1Client . getOAuthRequestToken = async ( params = { } ) => { return await new Promise ( ( resolve , reject ) => { originalGetOAuthRequestToken ( params , ( error , oauth_token , oauth_token_secret , params ) => { if ( error ) { return reject ( error ) ; } resolve ( { oauth_token , oauth_token_secret , params } as any ) ; } ) ; } ) ; } ; return oauth1Client ; }