feat(security): add SSO discovery and session token API endpoints#40024
feat(security): add SSO discovery and session token API endpoints#40024AlbertoSolaro wants to merge 1 commit into
Conversation
Add two new REST API endpoints to SecurityRestApi for external client applications (e.g. mobile apps) that consume Superset's APIs and need to discover configured SSO providers and exchange browser sessions for JWT bearer tokens: - GET /api/v1/security/auth_providers/ — returns configured auth providers (OAuth/SAML) with login URLs, auth type, and whether a browser flow is required. Does not require authentication. - GET /api/v1/security/session_token/ — converts an active cookie session into a JWT access token. Requires authentication. This addresses a gap where mobile and third-party applications that consume Superset's REST APIs need to programmatically discover login options and obtain API tokens after completing SSO flows in a web view. Real-world use case: Glimvia (https://www.glimvia.app/), a mobile application that leverages Superset's API for data visualization, requires these endpoints to authenticate users via SSO and interact with the API using bearer tokens. Implementation details: - JWT identity uses str(user.id) matching FAB's SecurityApi pattern - Anonymous users receive 401 with explicit guard - Provider login URLs use rstrip('/') for robust path construction - Full OpenAPI/Swagger documentation via docstrings - 6 integration tests covering DB auth, OAuth mock, unauthenticated access, and multi-role token generation
Code Review Agent Run #043a9eActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds two new REST API endpoints to SecurityRestApi to support external clients (e.g., mobile apps): one for discovering configured SSO providers and login URLs, and one for exchanging an authenticated browser session for a JWT access token. Includes integration test coverage for the new endpoints.
Changes:
- Add
GET /api/v1/security/auth_providers/(unauthenticated) to expose OAuth/SAML provider metadata and login URLs. - Add
GET /api/v1/security/session_token/(authenticated) that returns a JWT created from the active session viaflask_jwt_extended.create_access_token. - Add a
TestSecuritySsoApitest class covering DB auth, OAuth (mocked), unauth access, and admin/gamma token retrieval.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| superset/security/api.py | Implements auth_providers and session_token endpoints with OpenAPI docs. |
| tests/integration_tests/security/api_tests.py | Adds integration tests for new endpoints. |
| if auth_type == AUTH_OAUTH: | ||
| for provider in self.appbuilder.sm.oauth_providers: | ||
| name = provider["name"] | ||
| providers.append( | ||
| { | ||
| "name": name, | ||
| "icon": provider.get("icon", "fa-sign-in"), | ||
| "login_url": f"{login_base}/{name}", | ||
| } | ||
| ) | ||
| elif auth_type == AUTH_SAML: | ||
| for provider in self.appbuilder.sm.saml_providers: | ||
| name = provider["name"] | ||
| providers.append( | ||
| { | ||
| "name": name, | ||
| "icon": provider.get("icon", "fa-sign-in"), | ||
| "login_url": f"{login_base}/{name}", | ||
| } | ||
| ) |
| if auth_type == AUTH_OAUTH: | ||
| for provider in self.appbuilder.sm.oauth_providers: | ||
| name = provider["name"] | ||
| providers.append( | ||
| { | ||
| "name": name, | ||
| "icon": provider.get("icon", "fa-sign-in"), | ||
| "login_url": f"{login_base}/{name}", | ||
| } | ||
| ) | ||
| elif auth_type == AUTH_SAML: | ||
| for provider in self.appbuilder.sm.saml_providers: | ||
| name = provider["name"] | ||
| providers.append( | ||
| { | ||
| "name": name, | ||
| "icon": provider.get("icon", "fa-sign-in"), | ||
| "login_url": f"{login_base}/{name}", | ||
| } | ||
| ) | ||
|
|
| 500: | ||
| $ref: '#/components/responses/500' | ||
| """ | ||
| from flask_jwt_extended import create_access_token |
| 500: | ||
| $ref: '#/components/responses/500' | ||
| """ | ||
| auth_type = current_app.config.get("AUTH_TYPE") |
| if not user or user.is_anonymous: | ||
| return self.response_401() | ||
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40024 +/- ##
==========================================
- Coverage 63.88% 55.56% -8.33%
==========================================
Files 2583 2584 +1
Lines 136604 136729 +125
Branches 31502 31524 +22
==========================================
- Hits 87276 75968 -11308
- Misses 47812 60100 +12288
+ Partials 1516 661 -855
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
SUMMARY
Add two new REST API endpoints to SecurityRestApi for external client applications (e.g. mobile apps) that consume Superset's APIs and need to discover configured SSO providers and exchange browser sessions for JWT bearer tokens:
This addresses a gap where mobile and third-party applications that consume Superset's REST APIs need to programmatically discover login options and obtain API tokens after completing SSO flows in a web view.
Real-world use case: Glimvia (https://www.glimvia.app/), a mobile application that leverages Superset's API for data visualization, cannot implement SSO login because it is not exposed and API work amazing with JWT so converting it could be useful.
Implementation details:
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION