-
Notifications
You must be signed in to change notification settings - Fork 96
feat: Implementation of OAuth Device Code Flow #245
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for Device Access Tokens using OAuth Device Code Flow to the Helix Twitch API client. This enables authentication for standalone devices like game consoles and CLIs that may not have easy access to a web browser.
- Added
DeviceAccessTokenfield to theOptionsstruct and corresponding getter/setter methods - Implemented
RequestDeviceVerificationURIandRequestDeviceAccessTokenmethods for the device code flow - Updated token precedence logic in
setRequestHeadersto include device tokens (between app and user tokens)
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| helix.go | Added DeviceAccessToken field to Options struct, implemented getter/setter methods, updated token precedence logic, and modified canRefreshToken logic |
| helix_test.go | Added comprehensive test coverage for device access token functionality including getter/setter tests and token header priority tests |
| authentication.go | Implemented device code flow with RequestDeviceVerificationURI and RequestDeviceAccessToken methods and associated types |
| authentication_test.go | Added test cases for device verification URI and device access token requests |
| docs/authentication_docs.md | Added documentation for device access token flow including examples for getting and refreshing device tokens |
| docs/README.md | Updated documentation to include device access tokens in the Options struct and access token priority explanation |
| SUPPORTED_ENDPOINTS.md | Added device access token OAuth flow to the list of supported endpoints |
Comments suppressed due to low confidence (1)
helix.go:442
- The
refreshToken()method only handles user access token refresh by callingRefreshUserAccessTokenand updatingUserAccessToken. However, thecanRefreshToken()method now allows device tokens to pass through (line 423). When a device token is being used without a user token, the refresh will still callRefreshUserAccessToken, which may not be appropriate for device tokens. This could cause incorrect token refresh behavior.
func (c *Client) refreshToken() error {
resp, err := c.RefreshUserAccessToken(c.opts.RefreshToken)
if err != nil || resp.StatusCode != http.StatusOK {
statusCode := -1
var errorMessage string
if resp != nil {
statusCode = resp.StatusCode
errorMessage = resp.ErrorMessage
}
return fmt.Errorf("failed to refresh token: (%d: %s) %v", statusCode, errorMessage, err)
}
c.mu.Lock()
c.opts.UserAccessToken = resp.Data.AccessToken
c.opts.RefreshToken = resp.Data.RefreshToken
c.mu.Unlock()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
|
Reviewed Copilot suggestions and fixed them. |
nicklaw5
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Pull Request Test Coverage Report for Build 19297569553Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Added two new methods for generating DCF tokens, also tests and docs for them:
RequestDeviceVerificationURI()RequestDeviceAccessToken()New structs for requests/responses as well.
New methods
SetDeviceAccessToken()/GetDeviceAccessToken()forDeviceAccessTokeninOptions.Also tests for them too.
UserAccessTokenstill prioritized in headers overDeviceAccessToken, which is also prioritized overAppAccessToken.Argued against adding new method for refreshing DCF tokens, when existing
RefreshTokenalready works, as it doesn't return an error for missingClientSecret. Still open for consideration. Also updatedcanRefreshToken()to support both ACF and DCF at the same time.