Skip to content

Commit c245ccd

Browse files
Revert "Don’t use mwoauth.identify() to get user name"
This was poorly advised, as index.php told users to use a “user identification only“ consumer if they didn’t need any grants, but the authorization area would be broken in that case: such consumers aren’t allowed to use the API (error: readapidenied). I think the best solution is to switch back to mwoauth.identify(): yes, it’s not a great interface, but it’s better than only supporting “regular” OAuth consumers in the tool, or than introducing another prompt in cookiecutter.json asking which type of OAuth consumer users are intending to use, or than including the code for both versions and falling back from action='userinfo' to mwoauth.identify() if the former yields an error. This reverts commit a4b9d93. Bug: T403932
1 parent 8a89bd9 commit c245ccd

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

{{cookiecutter.tool_identifier}}/app.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ def authentication_area(){% if cookiecutter.set_up_mypy == "True" %} -> Markup{%
8888
Markup.escape(flask.url_for('login')) +
8989
Markup(r'">Log in</a></span>'))
9090

91-
userinfo = session.get(action='query',
92-
meta='userinfo')['query']['userinfo']
91+
access_token = mwoauth.AccessToken(
92+
**flask.session['oauth_access_token'])
93+
identity = mwoauth.identify(index_php,
94+
consumer_token,
95+
access_token)
96+
9397
return (Markup(r'<span class="nav-item navbar-text">Logged in as ') +
94-
user_link(userinfo['name']) +
98+
user_link(identity['username']) +
9599
Markup(r'</span>'))
96100

97101

{{cookiecutter.tool_identifier}}/templates/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ <h3>Register an OAuth consumer</h3>
230230
</p>
231231
<p>
232232
Select which rights you want access to, if any
233-
(otherwise select one of the “user identification only” options).
233+
(otherwise leave just the “basic rights” checked –
234+
or use a “user identity verification only” consumer and make sure to only use <code>mwoauth.identify()</code>,
235+
as seen in <code>authentication_area()</code>, and not <code>action='userinfo'</code>, as seen in <code>praise()</code>).
234236
This will highly depend on your tool,
235237
but “edit existing pages”, “create, edit and move pages” and “high-volume editing” are probably the most generally useful ones.
236238
</p>

0 commit comments

Comments
 (0)