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

feat(oauth-providers): Add Twitch OAuth Provider #981

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

Younis-Ahmed
Copy link
Contributor

@Younis-Ahmed Younis-Ahmed commented Feb 25, 2025

Add Twitch OAuth Provider

Which middleware is the feature for?

@hono/oauth-providers

What is the feature you are proposing?

This PR introduces a Twitch OAuth provider, expanding the middleware's OAuth offerings. It includes a new middleware for Twitch authentication, a dedicated AuthFlow class, token refreshing/revocation/validation, and comprehensive type definitions. Detailed tests ensure correct behavior and error handling. resolves #983

Key Changes

  • Twitch OAuth Middleware src/providers/twitch/twitchAuth.ts: Implements the core authentication flow, handling state management, redirects, and context variable setting (token, refresh-token, user-twitch, granted-scopes).

  • AuthFlow Class src/providers/twitch/authFlow.ts: Encapsulates token exchange and user data retrieval, with robust error handling.

  • Token Operations src/providers/twitch/refreshToken.ts, src/providers/twitch/revokeToken.ts): Provides functions for refreshing and revoking tokens.

  • Type Definitions src/providers/twitch/types.ts: Defines comprehensive types for Twitch API responses.

  • Extensive Testing (test/handlers.ts, test/index.test.ts): Includes unit tests covering redirection, valid code flow, error handling, refresh/revoke token, custom and built-in state scenarios, using a mock server.

  • Validate Token src/providers/twitch/validateToken: That hit /validate endpoint to verify that the access token is still valid for reasons other than token expiring.

    Example: if your app provides a Log in with Twitch feature, the user signs in to the app as a Twitch user, which creates an OAuth session for them. If the user disconnects the integration while still signed in, the expectation is that your app should sign out the user and terminate the OAuth session. To discover that the user has disconnected the integration, the app needs to call the /validate endpoint to determine that the token is no longer valid and to sign out the user.

Checklist

  • Create a validateToken that hit /validate endpoint to verify that the access token is still valid for reasons other than token exirping
  • Core Twitch OAuth flow implemented
  • Implemented AuthFlow with error handling
  • Added refresh/revoke token operations
  • Comprehensive TypeScript types
  • Extensive unit tests
  • Updated module declarations
  • Update Readme.md with examples
  • Add tests
  • Run tests
  • yarn changeset with summary
  • Follow contribution guide

Copy link

changeset-bot bot commented Feb 25, 2025

🦋 Changeset detected

Latest commit: b673173

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/oauth-providers Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Younis-Ahmed Younis-Ahmed marked this pull request as ready for review February 26, 2025 14:18
@yusukebe
Copy link
Member

@Younis-Ahmed thank you for the PR.

Hey @monoald, can you review this?

Copy link
Contributor

@BarryThePenguin BarryThePenguin left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍🏻

@Younis-Ahmed
Copy link
Contributor Author

Hi @BarryThePenguin

Thank you for the review, appreciate it

Changed version from patch to minor
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.

feat(oauth-providers): Adding Twitch oauth provider
3 participants