Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HTTP authentication #141

Merged
merged 1 commit into from
Oct 31, 2024
Merged

Conversation

gbenson
Copy link
Contributor

@gbenson gbenson commented Sep 5, 2024

This pull request adds support for HTTP authentication, by adding an http_auth argument and property to MediaWiki. Whatever you pass/set as http_auth gets passed to Requests as an auth parameter, so you can do any of these:

from requests.auth import HTTPBasicAuth
wiki = MediaWiki(..., http_auth=HTTPBasicAuth("username", "Pa5sW0rD"))

or:

wiki = MediaWiki(..., http_auth=("username", "Pa5sW0rD"))  # shortcut for basic auth

or:

from requests.auth import HTTPDigestAuth
wiki = MediaWiki(...)
wiki.http_auth=HTTPDigestAuth("username", "Pa5sW0rD")

@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.17%. Comparing base (98e2423) to head (f8ebd63).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #141   +/-   ##
=======================================
  Coverage   94.17%   94.17%           
=======================================
  Files           6        6           
  Lines        1219     1237   +18     
=======================================
+ Hits         1148     1165   +17     
- Misses         71       72    +1     
Files with missing lines Coverage Δ
mediawiki/configuraton.py 96.77% <100.00%> (-0.47%) ⬇️
mediawiki/mediawiki.py 91.40% <100.00%> (+0.15%) ⬆️

@barrust
Copy link
Owner

barrust commented Oct 19, 2024

With this PR, could or should the username and password options be removed? Also, are there open sites with examples of using this form of authentication?

@gbenson
Copy link
Contributor Author

gbenson commented Oct 23, 2024

With this PR, could or should the username and password options be removed?

No, it's a separate thing. The existing username and password are for your account on that particular wiki, they're checked and enforced by MediaWiki itself. The one I added are for HTTP authentication which is usually checked and enforced by the web server, e.g. with Apache you can do it by adding a .htaccess file to the MediaWiki directory on the server like this:

AuthType Basic
AuthUserFile /path/to/.htusers
AuthName "private wiki"
Require valid-user

The browser will pop up a box asking for the username and password before even touching any MediaWiki code.
(docs: Apache, nginx)

Also, are there open sites with examples of using this form of authentication?

Probably not, it's kind of a "total lockdown" form of site protection. I use it on a site I have for private notes, but I could probably set you something up if you need one for testing. Let me know!

@barrust barrust merged commit c55fc13 into barrust:master Oct 31, 2024
9 checks passed
@gbenson gbenson deleted the http-auth branch October 31, 2024 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants