Skip to content

feat(auth): add support for device code grant flow#5680

Open
Nerixyz wants to merge 28 commits intoChatterino:masterfrom
Nerixyz:experiment/device-auth
Open

feat(auth): add support for device code grant flow#5680
Nerixyz wants to merge 28 commits intoChatterino:masterfrom
Nerixyz:experiment/device-auth

Conversation

@Nerixyz
Copy link
Contributor

@Nerixyz Nerixyz commented Oct 27, 2024

This PR adds support for Twitch's Device code grant flow (DCF). This makes it possible to (effectively) use tokens for much longer without requiring the user to reauthenticate (assuming the scopes didn't change).

Currently, this uses a client-id I created (THIS MUST BE CHANGED BEFORE A MERGE). Because we use the public client type, the client-id is limited to DCF-only (as far as I understand).

(effectively) closes #5169.

Here's a cool video I took in February when I started this (hasn't changed much):

firefox_2024-02-11_12-24-45.mp4

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@jupjohn
Copy link
Contributor

jupjohn commented Oct 30, 2024

Been running this for a few days and seems solid 👍

@iProdigy
Copy link
Contributor

Should we validate that stored tokens have all of DEVICE_AUTH_SCOPES? (or perhaps should be tackled in a separate PR)

@Nerixyz
Copy link
Contributor Author

Nerixyz commented Oct 30, 2024

Should we validate that stored tokens have all of DEVICE_AUTH_SCOPES? (or perhaps should be tackled in a separate PR)

Twitch does that when we refresh tokens (the last time I tested it). The error you get there is pretty bad, though (iirc, it's the same one you get when the token is invalid). Should be enough to add a message with a link to re-authenticate.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@Nerixyz
Copy link
Contributor Author

Nerixyz commented Jan 26, 2025

Should we validate that stored tokens have all of DEVICE_AUTH_SCOPES? (or perhaps should be tackled in a separate PR)

I've done that now.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@Mm2PL
Copy link
Collaborator

Mm2PL commented Feb 1, 2025 via email

@Nerixyz
Copy link
Contributor Author

Nerixyz commented Feb 1, 2025

Then we will not be able to access public data about people who log in to Chatterino.

Only if we use an app access token. We don't use an app access token on the client.

@Mm2PL
Copy link
Collaborator

Mm2PL commented Feb 1, 2025 via email

@Nerixyz
Copy link
Contributor Author

Nerixyz commented Feb 1, 2025

As I understand it the problem is that we cannot give each client a direct connection to Twitch EventSub due to limits on conduits and their rate limits and thus we must build our own pubsub.

We connect to eventsub locally via websockets.

@iProdigy
Copy link
Contributor

iProdigy commented Feb 1, 2025

DCF works for normal eventsub websocket (but we won't be able to get redemptions events if not the broadcaster)

we will never use app token client-side (would require each user to create a dev app to obtain a client secret)

but yes my server-side conduit RFC wouldn't work if we switched auth to DCF (unless we forced streamers to continue authing from the website)

@Mm2PL
Copy link
Collaborator

Mm2PL commented Mar 11, 2025 via email

@Wissididom
Copy link
Contributor

@Mm2PL
Copy link
Collaborator

Mm2PL commented Mar 16, 2025 via email

@iProdigy
Copy link
Contributor

iProdigy commented Mar 16, 2025

if we want to pursue the RFC, at the end of the device flow, we can display a message asking streamers to also auth with the website (hyperlinked) - but we can have a separate page that just says Success; you may now close this tab on redirect instead of yielding a copy-able access token to avoid confusion

(this can be done in a separate pr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments