Added WordPress Authentication Plugin#1954
Conversation
flexget/plugins/sites/wordpress.py
Outdated
| log = logging.getLogger('wordpress_auth') | ||
|
|
||
|
|
||
| class WPLoginHeaders(dict): |
There was a problem hiding this comment.
I'm not sure I like this. Why not just create a regular dict in on_task_start? Same goes for the other classes.
There was a problem hiding this comment.
I guess I'm pretty new to the python way of doing things.
I created the WPLogin Classes so that I could have a very clean
get_cookies(WPSession(), WPLoginRequest(url, username=username, password=password).prepare())with WPSession and WPLoginRquest dependency injected into get_cookies
rather than having to imperatively write
wpsession = Session()
wpsession.max_redirects = 5
wp_login_request = Request()
#etcI felt it was a way to keep the on_task_start function short.
Again,
I don't have a very strong background in python, I'm more familiar with compiled languages.
So maybe this type of reasoning is faulty.
flexget/plugins/sites/wordpress.py
Outdated
| log = logging.getLogger('wordpress_auth') | ||
|
|
||
|
|
||
| def _get_wp_login_data(username='', password='', redirect='/wp-admin/'): |
There was a problem hiding this comment.
Is there any reason to have these as separate functions/classes is what I was thinking...
There was a problem hiding this comment.
no, there isn't
cleaning it up now
flexget/plugins/sites/wordpress.py
Outdated
| username = config['username'] | ||
| password = config['password'] | ||
|
|
||
| resp = send_request(Session(), construct_wp_login_request(url, username=username, password=password)) |
There was a problem hiding this comment.
Use task.requests instead of Session() and don't close it.
There was a problem hiding this comment.
Good, idea. Done
flexget/plugins/sites/wordpress.py
Outdated
|
|
||
| resp = send_request(Session(), construct_wp_login_request(url, username=username, password=password)) | ||
| cookies = collect_cookies_from_response(resp) | ||
| validate_cookies(cookies, match_wordpress_cookie) |
There was a problem hiding this comment.
Not sure what the point of this is. Should the task just continue if the cookies are invalid?
There was a problem hiding this comment.
That was the initial thought. That the task should continue, the reasoning behind it was that in the future, wordpress might update the cookie names. However, that doesn't seem likely and in the event they do such a thing this plugin would need to be updated. I've changed the code so that the task will abort if there are no valid cookies found.
flexget/plugins/sites/wordpress.py
Outdated
| return re.match(r'wordpress(?!_test)[A-z0-9]*', key, re.IGNORECASE) | ||
|
|
||
|
|
||
| def send_request(session, prep_request, redirects=5): |
There was a problem hiding this comment.
I'd honestly prefer having this inside on_task_start. You generally create a lot of global functions that could just as well be made inline in on_task_start.
I think the code becomes harder to read when having to scroll up and down to see what each function does. construct_wp_login_request is also just essentially two dicts.
It looks fine otherwise. I just don't agree with the code style.
There was a problem hiding this comment.
I've updated the code now so there are only 3 global functions.
The request is now sent in on_task_start
All exceptions are now handled or raised in on_task_start
|
Has this PR gone stale? |
|
A little... |
|
The format of the authentication that the WordPress site requires is not standard form authentication. The username is submitted under the |
|
Gotcha. |
|
Yeah, the wiki is updated. |
Motivation for changes:
I wanted to access an rss feed that required WordPress Authentication. WordPress uses cookies for authentication and they expire quickly. I was sick of using the headers plugin and having to update it every couple days. WordPress cookies are obtained through a
POSTrequest to awp-login.phppage with data of the form:WordPress will return cookies for authentication in the form:
Detailed changes:
task startthewordpress_authplugin sends a request to the WordPress login page with the URL, username, and password specified in the configtask.requestsAddressed issues:
Added new plugin
wordpress_authImplemented feature requests:
Config usage if relevant (new plugin or updated schema):
Log and/or tests output (preferably both):
PyCharm says all the tests pass or are skipped.
I don't know what all the errors in the log are.
To Do: