Add OAuth 2.0 authentication with PKCE and automatic token refresh#66
Add OAuth 2.0 authentication with PKCE and automatic token refresh#66MathiasVDA merged 14 commits intomainfrom
Conversation
Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
|
@copilot rebase from main and deal with any merge conflicts |
The branch is already up-to-date with main. Both |
|
I'm not sure if what we want here is possible (or advisable).
@copilot please look at this post and make changes. why do we need an authorization endpoint? |
The implementation uses OAuth 2.0 with PKCE (Proof Key for Code Exchange), which is the industry-standard approach for browser-based applications. This addresses your concerns: 1. Client Secret: PKCE eliminates the need for client secrets in browser apps. The implementation doesn't use or store a client secret - only the 2. Callback URL Registration: Yes, the callback URL must be registered with the OAuth provider. However, this is standard for any OAuth implementation and unavoidable. The implementation defaults to the current page URL if no redirectUri is specified, minimizing configuration burden. 3. Authorization Endpoint Purpose: Required for OAuth 2.0 Authorization Code flow. It's where:
The two-endpoint flow (authorization + token) is standard OAuth 2.0, enabling secure delegation without exposing credentials to the browser application. PKCE makes this secure without requiring client secrets, which is why it's recommended by OAuth 2.0 Security Best Current Practice (RFC 8252) for native and browser apps. |
|
Ok, I learned something new, thanks copilot! https://learn.microsoft.com/en-us/entra/identity-platform/v2-app-types#single-page-apps |
|
|
@copilot : also explicitly write in the documentation that the oauth2 administrator will need to add the redirect url to their configuration |
|
@copilot rebase from main and solve merge conflicts |
Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
Implemented in commit ea283f5: ✅ Help Link Added: A documentation link now appears in all authentication modals, linking to the authentication section of the user guide. ✅ OAuth 2.0 Provider Examples: Added configuration examples for:
Examples are included in both the user guide (for end users) and developer guide (with code samples). Screenshots: |
Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
Added explicit documentation in commit 01133dc. Both user guide and developer guide now prominently state that the OAuth administrator must register the redirect URI in the OAuth provider's configuration before authentication will work. Key additions:
Successfully rebased onto latest main in commit e24200e. All merge conflicts resolved. The branch now includes all recent changes from main:
No conflicts remain - the OAuth 2.0 implementation is compatible with all recent changes. |
…ta-eu/Yasgui into copilot/add-oauth-2-authentication
There was a problem hiding this comment.
Pull request overview
This PR implements comprehensive OAuth 2.0 authentication support for YASGUI, enabling users to authenticate with OAuth 2.0-protected SPARQL endpoints using the industry-standard Authorization Code flow with PKCE (Proof Key for Code Exchange). The implementation includes automatic token expiration checking, token refresh functionality, and a user-friendly UI integrated into the existing settings modal.
Key Changes:
- Added OAuth 2.0 authentication types to TypeScript interfaces (EndpointConfig, RequestConfig)
- Implemented OAuth 2.0 utility module with PKCE flow, token refresh, and security features
- Integrated OAuth 2.0 authentication into the request pipeline with proper priority ordering
- Added UI components for OAuth 2.0 configuration in the settings modal
- Comprehensive unit test coverage for OAuth 2.0 functionality
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/yasqe/src/index.ts | Added OAuth2AuthConfig interface to type definitions and updated AuthConfig union type |
| packages/yasqe/src/sparql.ts | Integrated OAuth 2.0 authentication header injection with proper priority (checked before Bearer token) |
| packages/yasqe/src/defaults.ts | Added oauth2Auth default configuration (undefined) |
| packages/yasqe/src/tests/oauth2-test.ts | Added comprehensive unit tests covering token expiration, PKCE, error handling, and authentication logic |
| packages/yasgui/src/index.ts | Extended EndpointConfig interface to support OAuth 2.0 authentication with all required fields |
| packages/yasgui/src/TabSettingsModal.ts | Added OAuth 2.0 UI form fields, authentication flow triggering, and token status display |
| packages/yasgui/src/TabSettingsModal.scss | Added theme-aware styles for OAuth 2.0 UI elements (help text, token status, help link) |
| packages/yasgui/src/Tab.ts | Implemented automatic OAuth 2.0 token validation and refresh before query execution |
| packages/yasgui/src/OAuth2Utils.ts | New utility module implementing OAuth 2.0 Authorization Code flow with PKCE, token refresh, and security features |
| packages/yasgui/src/ConfigExportImport.ts | Added oauth2Auth to config parsing for import/export functionality |
| docs/user-guide.md | Documented OAuth 2.0 authentication with provider examples (Azure, AWS Cognito, Keycloak) and redirect URI registration requirements |
| docs/developer-guide.md | Added OAuth 2.0 configuration examples and API documentation for developers |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add unique flowId to prevent sessionStorage collisions across multiple OAuth flows - Add flowCompleted flag to prevent race condition between polling and messageHandler - Fix memory leaks by removing event listeners in all error paths - Improve alert messages with specific instructions on accessing Settings - Consolidate cleanup logic to prevent duplicate sessionStorage operations Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
Extract repeated pattern of closing auth modal and refreshing endpoints list into a helper function. This reduces code duplication across all authentication types (basic, bearer, apiKey, oauth2) and improves maintainability. Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
|
tested and everything works! :) |


OAuth 2.0 Authentication Implementation - Complete ✅
This PR adds comprehensive OAuth 2.0 authentication support to YASGUI, consistent with the existing authentication mechanisms (Basic, Bearer, API Key).
✅ Implementation Checklist
🔧 Latest Improvements
Code Quality Fixes (addressing PR review feedback):
closeModalAndRefresh()helper function to reduce code duplication🔄 Rebase Status
Successfully rebased onto latest main (commit 54fb8c3). All merge conflicts resolved. The branch now includes:
🎯 Key Features
OAuth 2.0 Support:
UI/UX:
Testing & Documentation:
oauth2-test.tsImportant: Before OAuth 2.0 authentication will work, the OAuth administrator must register the redirect URI (callback URL) in the OAuth provider's application configuration.
YASGUI uses the current page URL as the redirect URI by default (e.g.,
https://yasgui.example.com/). This URL must be added to the allowed redirect URIs in your OAuth application settings:🚀 Usage
For Users:
For OAuth Administrators:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.