Add Django OAuth login with Pywikibot integration - #135
Conversation
- Add Django Social Auth with MediaWiki OAuth 1.0a backend - Configure OAuth callback URL with trailing slash - Add login/logout views and URL routes - Update UI with login button in top right corner - Implement configure_pywikibot_oauth() helper function
|
Hi @zache-fi, The OAuth implementation is complete and tests pass, but I'm hitting 403 Forbidden errors when testing the full OAuth flow from localhost (even after registering OAuth consumers with proper callback URLs on meta.wikimedia.org). How do you typically test OAuth locally for this project? Should I use ngrok for a public URL, test on a deployed environment, or is there another approach you recommend? The code looks correct based on Django Social Auth docs, but I can't verify the end-to-end flow due to this localhost limitation. Everything is documented in the OAUTH_TESTING_GUIDE.md. |
|
Hi, try to register it at meta.wikimedia.beta.wmflabs.org/ and use it as endpoint. It doesn't work for superset, but I can approve ouths there so registering and finding correct value can be done trial and error. |
|
Just FYI. I can test the correct values. |
|
Note https://meta.wikimedia.beta.wmcloud.org doesn't use wikimedias unified login so you need to register separate account there. Oauth consumer registration
settings.py |
|
Btw is beta blocked for you? |
- Keep social-auth-app-django for OAuth - Keep upstream type checking and security tools
- Changed default SOCIAL_AUTH_MEDIAWIKI_URL to meta.wikimedia.beta.wmcloud.org - Updated OAUTH_TESTING_GUIDE.md with Zache's specific registration instructions
|
Yes, the login works now. There could be still couple of changes. Fix the Add to the top of the page navigation bar (similarly than in https://wikikysely-dev.toolforge.org/en/ ) and move the login button to top right of the bar. This just to make it look nicer. Another change would be that save the actual Wikimedia Commons username . (Reusing Djangos first_name field would be OK as we arent using it anywhere and would not require any user model customization ) This is because Django will "normalize" usernames (ie removes high-bit characters for example) before saving it to username field so it cannot be used for showing the username. Try if you can pass the Oauth credidentials to pywikibot instance after you have logged in. If Oauth endpoint used for login is If you have logged in using Here is example code Note you need login commons once so it will create a user to target wiki before this work. |
- Add top navigation bar with login button in top-right corner - Save original Wikimedia username in first_name field (avoid normalization) - Update Pywikibot OAuth config to use beta/production appropriately - Configure pywikibot.config.usernames based on OAuth endpoint - Display first_name (original username) in navbar if available - Fix ruff formatting issues
|
Hi @zache-fi! Thanks for the feedback! Please let me know next steps. |
|
check why the test is failing and fix it |
|
Thanks for catching that. I think it's a template syntax issue with Vue. Let me take a more keen look. Thanks |
- Replace Vue.js syntax with v-text directive to avoid Django parser conflicts - Remove verbatim tags as they're no longer needed with v-text
|
Hi @sergyDwhiz! 👋 Excellent work on the OAuth integration! I've reviewed the code and tested it locally. This is a crucial ✅ What Works WellArchitecture:
Pywikibot Integration:
UI/UX:
Testing & ObservationsI tested this locally with the following scenarios: Scenario 1: OAuth Login Flow
Scenario 2: OAuth Disabled Mode
Scenario 3: Pywikibot Integration
Minor Suggestions1. Error Messaging: # In views or middleware
except SocialAuthException as e:
messages.error(request, "OAuth login failed. Please try again or contact support.")
2. Session Timeout:
Consider documenting the session timeout behavior. Users should know how long they stay logged in.
3. Testing Documentation:
It would be helpful to add a section in the README about:
- How to set up beta OAuth consumer for testing
- Environment variables needed
- Common troubleshooting steps
Great foundational work! 🚀
## If you need assistance with:
- Writing additional tests for edge cases
- Resolving any test failures
- Adding documentation
- Testing with production-like scenarios
I'm happy to collaborate! We could pair on this to get it across the finish line. |
- Fixed Django/Vue.js template syntax conflicts reintroduced by merge
|
Hi @xenacode-art, sorry for my late reply. I've been through a lot. Thanks so much for the thorough review and testing. I appreciate you taking the time to verify everything works! Your suggestions about error messaging, session timeout documentation and testing are true. I've been working on a fix for the template syntax conflicts that came back after the merge. Pushing it soon. |
|
@sergyDwhiz glad to have you back hope you're doing okay. |
|
Thanks bro, and I'm good. Hope same? |
|
We need to do everything to close this PR sooner bro. It's a crucial feature. |
This pull request integrates Django Social Auth with the MediaWiki OAuth 1.0a backend, enabling users to authenticate using their Wikimedia accounts.
Changes made include:
Addresses: #117