cubehouse / themeparks

Unofficial API for accessing ride wait times and schedules for Disneyland, Disney World, Universal Studios, and many more parks
MIT License
536 stars 126 forks source link

fix(universal): properly pass token ttl to cache #316

Closed evanlanglais closed 3 years ago

evanlanglais commented 3 years ago

Pass the received access token TTL to the Cache.Wrap function through a lambda to capture value reference.

Closes #304

evanlanglais commented 3 years ago

To add a bit of context as to why this fix is needed:

The receivedTtl value, assigned with token ttl value of the auth HTTP POST request, is not actually passed by reference to the Cache.Wrap function. Instead, the value of receivedTtl at the time of calling Cache.Wrap, null, is passed and subsequently used, causing the default cache ttl to be used instead of the received one, resulting in the auth 401 error documented in #304

By passing a lambda which immediately resolves to the receivedTtl value, it pulls the reference to that variable all the way into the Cache function, and because the data function is resolved before reading the ttl value it should always resolve to the proper ttl returned by the auth request.

cubehouse commented 3 years ago

Excellent find.

Thank you for the pull request!