A standards-compliant OAuth2 application for Flows that implements the authorization code flow with automatic token refresh.
This app provides OAuth2 authentication for external services, automatically managing tokens and exposing them as signals for use in other blocks.
- Access Token block: Expose OAuth2 tokens as block-level signals for use in your flows
- Install the app in your Flows environment
- Configure OAuth2 endpoints - Authorization URL and Token URL
- Register with provider - Follow the prompt to register your OAuth2 application
- Authorize - Click the prompt button to authorize the application
- Use the Access Token block - Add it to your flow to access OAuth2 tokens as block signals
- Standards-compliant OAuth2: Implements RFC 6749 authorization code flow
- Automatic token refresh: Uses refresh tokens to maintain authentication
- CSRF protection: State parameter validation on callbacks
- Secure storage: Sensitive tokens stored securely, never exposed
- Block-level signals: Access Token block exposes tokens as signals for use in flows
- Flexible configuration: Support for custom scopes, audiences, and additional parameters
├── .github/workflows/ci.yml # CI/CD pipeline
├── main.ts # OAuth2 app definition with token management
├── blocks/
│ ├── index.ts # Block registry
│ └── accessToken.ts # Access Token block
├── package.json # Dependencies
└── README.md # This file
- Authorization URL: The OAuth2 authorization endpoint (e.g.,
https://provider.com/oauth/authorize) - Token URL: The OAuth2 token endpoint (e.g.,
https://provider.com/oauth/token)
- Client ID: OAuth2 client identifier (configured after provider registration)
- Client Secret: OAuth2 client secret (configured after provider registration)
- Scope: Space-separated OAuth2 scopes (e.g.,
read write) - Additional Authorization Parameters: JSON object with extra params for authorization request
- Additional Token Parameters: JSON object with extra params for token request
Authorization URL: https://github.com/login/oauth/authorize
Token URL: https://github.com/login/oauth/access_token
Scope: repo user (or as needed)
Note: GitHub OAuth tokens don't expire by default. The app will default to checking every hour, but the token remains valid until revoked.
GitHub-specific considerations:
- GitHub returns tokens as
application/x-www-form-urlencodedby default - The app automatically handles this by requesting JSON responses via the
Acceptheader - Refresh tokens are available if you include the
refresh_tokenscope
Authorization URL: https://accounts.google.com/o/oauth2/v2/auth
Token URL: https://oauth2.googleapis.com/token
Scope: (depends on API - e.g., https://www.googleapis.com/auth/userinfo.email)
Authorization URL: https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize
Token URL: https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token
Scope: (depends on API - e.g., https://graph.microsoft.com/.default)
Most OAuth2 providers follow a similar pattern:
Authorization URL: https://provider.com/oauth/authorize
Token URL: https://provider.com/oauth/token
Check your provider's documentation for:
- The correct endpoint URLs
- Available scopes
- Any provider-specific parameters needed
- Initial Setup: User configures Authorization URL and Token URL
- Provider Registration: Prompt guides user to register OAuth2 app with provider
- Authorization: User clicks prompt button → redirects to provider → authorizes app
- Callback: Provider redirects back to
/callbackwith authorization code - Token Exchange: App exchanges code for access token and refresh token
- Ready: Access token exposed as signal, available for use in blocks
- Scheduled check every 10 minutes
- Automatically refreshes token 5 minutes before expiration
- Uses refresh token if available
- Falls back to authorization code if refresh fails
- Updates all Access Token blocks when tokens are refreshed
- CSRF Protection: State parameter validated on OAuth callback
- Secure Storage: Client secrets and tokens stored securely in KV store
- Sensitive Signals: Access token marked as sensitive, never exposed in logs
- HTTPS Only: OAuth callback requires HTTPS in production
- Node.js 20+
- npm
npm install # Install dependencies
npm run typecheck # Type checking
npm run format # Code formatting
npm run bundle # Create deployment bundleExposes OAuth2 tokens as block-level signals. Automatically stays synchronized with the app's token state.
Signals:
- accessToken: OAuth2 bearer token (sensitive)
- expiresAt: Unix timestamp when token expires
Use case: When you need to reference OAuth2 tokens as block-level signals in your flows instead of using app-level signals.
- Verify Authorization URL and Token URL are correct
- Check that Redirect URI in provider matches:
{appEndpointUrl}/callback - Ensure Client ID and Client Secret are correct
- Check provider logs for error details
- Verify provider supports refresh tokens
- Check that refresh token was returned in initial token response
- Some providers (like GitHub) don't expire tokens, so refresh isn't needed
- Check token hasn't been revoked in provider
- Verify the scope includes necessary permissions
- Try re-authorizing the application
This implementation follows:
- RFC 6749: The OAuth 2.0 Authorization Framework
- Authorization Code Grant: Section 4.1
- Refresh Token: Section 6
MIT