Fix flask initdb error: migrate to Authlib 1.x#26
Open
wadelhw wants to merge 2 commits intoauthlib:masterfrom
Open
Fix flask initdb error: migrate to Authlib 1.x#26wadelhw wants to merge 2 commits intoauthlib:masterfrom
wadelhw wants to merge 2 commits intoauthlib:masterfrom
Conversation
Authlib 0.13 imports flask._app_ctx_stack which was removed in Flask 2.3+. Bumping to Authlib>=1.0 resolves the ImportError on modern Flask versions. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Adapts oauth2.py and routes.py to Authlib 1.x breaking changes: - create_authorization_code -> save_authorization_code (new signature) - parse_authorization_code -> query_authorization_code - validate_consent_request -> get_consent_grant - get_jwt_config now receives client parameter - request object uses .payload and .client attributes - Blueprint name fixed for Flask 3.x (no dots allowed) Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #19 —
flask initdbfails withImportError: cannot import name '_app_ctx_stack' from 'flask'when using modern Flask (3.x) with Authlib 0.13.Root Cause
Authlib 0.13 imports
flask._app_ctx_stack, which was removed in Flask 2.3+. The unpinnedFlaskandFlask-SQLAlchemydependencies resolve to Flask 3.1.x and Flask-SQLAlchemy 3.1.x, causing the import failure at app startup.Changes
requirements.txt
Authlib==0.13→Authlib>=1.0website/oauth2.py — Migrated to Authlib 1.x API:
create_authorization_code→save_authorization_code(new signature: code + request instead of client + grant_user + request)parse_authorization_code→query_authorization_codeexists_noncenow usesrequest.payload.client_id(Authlib 1.x request structure)get_jwt_confignow receivesclientparameter for OpenIDCode, ImplicitGrant, HybridGrantrequest.client,request.payload,request.user)website/routes.py
Blueprint(__name__, 'home')→Blueprint('home', __name__)(Flask 3.x rejects dots in Blueprint names)validate_consent_request→get_consent_grant(Authlib 1.x rename)Testing
pip install -r requirements.txtinstalls successfully (Authlib 1.6.9, Flask 3.1.3, Flask-SQLAlchemy 3.1.1)flask initdbruns without errors and creates the SQLite database