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

Require OAuth for search engine checks #52

Merged
merged 2 commits into from
Oct 4, 2024
Merged

Require OAuth for search engine checks #52

merged 2 commits into from
Oct 4, 2024

Conversation

ChlodAlejandro
Copy link
Collaborator

@ChlodAlejandro ChlodAlejandro commented Oct 4, 2024

This PR adds the initial backend requirements for the OAuth flow and makes authentication required for all uncached search engine checks. This adds three new routes:

  • /login (GET, POST) - for logging in
  • /logout (GET, POST) - for logging out
  • /oauth-callback - OAuth 1.0a callback route, used by MediaWiki

This requires the following .earwigbot/config.yml values:

  • wiki.copyvios.oauth.consumer_token
  • wiki.copyvios.oauth.consumer_secret

This requires a new file in the root folder (on Toolforge, ~/git/copyvios/) named config.py, to be used by Flask. This has already been added on Toolforge. This should export a single value, SECRET_KEY, which will be used to encrypt session data. An example config.py file can be as follows:

__all__ = ["SECRET_KEY"]

# Generate with `import secrets; print(secrets.token_urlsafe(48))`
SECRET_KEY = "TEST"

This adds mwoauth==0.3.8 as a requirement. 0.4.0 is not a possible version since it is Python 3.x-only. There doesn't seem to be any significant differences between the two which would be detrimental to the auth flow.

Login/logout state can be checked through the page header. By default, a separate page navigation is not required when the link is clicked by the user. When following a link to /log(in|out), however, an extra button will be shown to prevent inadvertent logins/logouts.

Cached data is still shown to unauthenticated users when available.

The commit which enables the requirement is separated to make it easily revertible in case something bad happens during deployment.

@ChlodAlejandro
Copy link
Collaborator Author

ChlodAlejandro commented Oct 4, 2024

Holding this until 14:00 UTC (or slightly later) to wait for comments from Earwig, then will deploy to Toolforge.

@ChlodAlejandro ChlodAlejandro force-pushed the feat/auth branch 4 times, most recently from 984943b to cb72361 Compare October 4, 2024 09:32
@ChlodAlejandro
Copy link
Collaborator Author

Just added a workflow speedup: the query attempted at request time should be run immediately after finishing the auth flow.

Copy link
Owner

@earwig earwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good aside from a couple minor comments!

templates/login.mako Outdated Show resolved Hide resolved
copyvios/checker.py Show resolved Hide resolved
Copy link
Owner

@earwig earwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple more.

copyvios/checker.py Outdated Show resolved Hide resolved
templates/login.mako Outdated Show resolved Hide resolved
Adds the initial backend requirements for the
OAuth flow, which will be made required for all
search engine checks. This adds three new routes:

- `/login` (GET, POST) - for logging in
- `/logout` (GET, POST) - for logging out
- `/oauth-callback` - OAuth 1.0a callback route

Login/logout state can be checked through the
header. By default, a separate page navigation is
not required when the link is clicked by the user.
When following a link to `/log(in|out)`, however,
an extra button will be shown to prevent inadvertent
logins/logouts.
Begin requiring OAuth for search engine checks.
This adds an extra validation step in checker.py.
It occurs after a cached result is checked for, which
allows unauthenticated viewers to still preview cached
results.
@earwig earwig merged commit 5c0a2d4 into main Oct 4, 2024
@earwig earwig deleted the feat/auth branch October 4, 2024 23:14
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.

2 participants