whatadewitt / yahoo-fantasy-sports-api

NodeJS wrapper for the Yahoo! Fantasy Sports API
https://yahoo-fantasy-node-docs.vercel.app/
MIT License
192 stars 52 forks source link

Access when signing in via Firebase Yahoo auth #113

Closed Wintersboy closed 4 months ago

Wintersboy commented 4 months ago

Hey there!

I was wondering if it's possible to still utilize this library when signing in with Yahoo via Firebase Auth? I'm able to sign in and grab the access token, which I tried to set in the backend like this:

const yf = new YahooFantasy(
  process.env.YAUTH_KEY,
  process.env.YAUTH_SECRET,
  null,
  process.env.YAUTH_CB
);

router.get('/yahoo/user/:id', async (req, res) => {
  const accessToken = req.query.accessToken

  yf.setUserToken(accessToken);

  try {
    const userGames = await yf.user.games();
    console.log('userGames :>> ', userGames);

  } catch (error) {
    console.log('error :>> ', error);
  }
})

Unfortunately, I'm getting this error:

error :>>  {
  lang: 'en-US',
  description: 'Please provide valid credentials. OAuth oauth_problem="token_rejected", realm="yahooapis.com"'
}

Is this method even possible? I don't see why it wouldn't.

Cheers!

whatadewitt commented 4 months ago

Whenever I've attempted to use Firebase Auth I've found they don't send the refresh token so I always kind of bailed then... If you're getting an access token from them then you SHOULD be getting a valid access token... can you try hitting one of their other "open" APIs directly and see if you get the same error?

Wintersboy commented 4 months ago

Could you point me to one of these "open" API's please?

whatadewitt commented 4 months ago

Wow... I just realized the only thing they have on their developer site is the fantasy api...

https://developer.yahoo.com/api/

With Firebase you are configuring to get the FantasySports scopes, yes?

Wintersboy commented 4 months ago

Lol yup, and its poorly documented.

As far as I'm aware, Firebase itself doesn't manage those permissions, it's the ones set in the Yahoo Developer section. Which yes, I do have set to read.

image

whatadewitt commented 4 months ago

Does the sign-in work, and it's just in the library that it breaks? I feel like I reached out to Firebase years ago about this issue but I can't find or remember where it ended.

My immediate thought is that something is happening at the Firebase Layer that is handling the actual auth with Yahoo! and it's returning you a different key.

Do you require the Firebase user settings you gain from using auth through them? I've done my best to make the library as easy as possible to login and obtain a token with... you could still leverage a lot of the other Firebase APIs?

Wintersboy commented 4 months ago

Yeah just tested signing in without Firebase and using your libraries method, and it works. My worry was also that Firebase uses its own access token instead of the one provided from Yahoo as well...

I don't NEED Firebase, I just thought it would be a simpler solution for managing auth.

Your library now automatically refreshes the access token correct?

whatadewitt commented 4 months ago

It should, yes!

I'm going to close this down just because I think we can mark it as "resolved"? ... there's a workaround at least...