twitter-api-typescript-sdk icon indicating copy to clipboard operation
twitter-api-typescript-sdk copied to clipboard

Enable constructing a authClient with a token

Open tevonsb opened this issue 3 years ago • 6 comments

I have a token stored for multiple users. However the current sdk does not offer an option for me to auth.OAuth2User object using a token that I already have. Instead I always need to request an authUrl to set the internal this.token parameter.

This makes the auth.OAuth2User object nearly unusable since the instance will not persist, and is used by multiple different users.

I think there should be a setToken method or similar, so I can internally set the token, and then us the isTokenExpired and refreshAuthToken methods as normal.

tevonsb avatar Aug 16 '22 18:08 tevonsb

Absolutely agree, the workarounds and open PR for this issue are very complicated for a simple bot example.

https://github.com/twitterdev/twitter-api-typescript-sdk/issues/25 https://github.com/twitterdev/twitter-api-typescript-sdk/pull/42

apecollector avatar Oct 14 '22 05:10 apecollector

This is my workaround, you can do the same until the feature is implemented:

https://github.com/roj1512/rtwtrbt/blob/main/auth.ts

rojvv avatar Oct 14 '22 10:10 rojvv

Simply, in your app, you can just extend the main auth class.

rojvv avatar Oct 14 '22 10:10 rojvv

+1 Working with this SDK on the backend is pretty rough, every time the backend restarts I need to go manually and set a new token.

ugglr avatar Dec 06 '22 06:12 ugglr

every time the backend restarts I need to go manually and set a new token.

This is not related to this library. Twitter revokes the token after a couple of hours if you or your backend don't refresh it.

rojvv avatar Dec 06 '22 10:12 rojvv

every time the backend restarts I need to go manually and set a new token.

This is not related to this library. Twitter revokes the token after a couple of hours if you or your backend don't refresh it.

What you describe is the correct behavior, that's why we have a refresh token.

What I'm referring to is related to this library, I store the refresh token in my database, but I cannot use it when the access token expires.

ugglr avatar Dec 07 '22 04:12 ugglr