Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce token cache #22

Closed
snobu opened this issue Mar 27, 2020 · 2 comments
Closed

Introduce token cache #22

snobu opened this issue Mar 27, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@snobu
Copy link
Owner

snobu commented Mar 27, 2020

We need a token cache that:

  • Saves the access token (preferably encrypted) to local storage (~/.destreamer/token.cache or something like that to be consistent with every other project out there that needs to save state).
  • Decodes the token on every run, looks at the expiration date and decides if we still need to pop up a browser window to acquire a new token or we can proceed without user interaction.

This will dramatically improve the user experience since within the span of one hour (Azure AD issues tokens with 1-hour lifetime) users can download videos without having to log back in.

Decode sample:

import * as jwt_decode from 'jwt-decode';

const token = 'eyJ0eXAi...';
const decoded = jwt_decode(token);

let now = Math.floor(Date.now() / 1000);
let exp = decoded['exp'];
let timeLeft = exp - now; // seconds

Stretch goal:

  • Can we get an access token for https://*.microsoftstream.com just by doing an Open ID connect / OAuth 2.0 dance using the default system browser (drop puppeteer altogether).

Implementation in progress. See tokencache branch for status.

@snobu snobu pinned this issue Mar 27, 2020
@snobu snobu added the enhancement New feature or request label Mar 27, 2020
@snobu snobu self-assigned this Apr 1, 2020
@lukaarma lukaarma moved this from To do to In progress in Destreamer 2.0 (tokencache will become master) Apr 8, 2020
@snobu snobu unpinned this issue Apr 9, 2020
@snobu snobu moved this from In progress to Review in progress in Destreamer 2.0 (tokencache will become master) Apr 9, 2020
@lukaarma
Copy link
Collaborator

It's working great, the only issue we may have is if the token expires mid-download but for that there is already #43

@snobu
Copy link
Owner Author

snobu commented Apr 10, 2020

Closing since token cache has been implemented. Tracking /refreshtoken implementation via #43

@snobu snobu closed this as completed Apr 10, 2020
Destreamer 2.0 (tokencache will become master) automation moved this from Review in progress to Done Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Development

No branches or pull requests

2 participants