Pass user agent header for OAuth
This commit is contained in:
parent
591ffa6055
commit
b78807d86b
1 changed files with 5 additions and 2 deletions
7
app.py
7
app.py
|
|
@ -43,6 +43,7 @@ from depicts import (
|
||||||
wikibase,
|
wikibase,
|
||||||
wikidata_edit,
|
wikidata_edit,
|
||||||
wikidata_oauth,
|
wikidata_oauth,
|
||||||
|
user_agent_headers,
|
||||||
)
|
)
|
||||||
from depicts.error_mail import setup_error_mail
|
from depicts.error_mail import setup_error_mail
|
||||||
from depicts.model import (
|
from depicts.model import (
|
||||||
|
|
@ -330,8 +331,9 @@ def start_oauth() -> Response:
|
||||||
base_url = "https://www.wikidata.org/w/index.php"
|
base_url = "https://www.wikidata.org/w/index.php"
|
||||||
request_token_url = base_url + "?title=Special%3aOAuth%2finitiate"
|
request_token_url = base_url + "?title=Special%3aOAuth%2finitiate"
|
||||||
|
|
||||||
|
headers = user_agent_headers()
|
||||||
oauth = OAuth1Session(client_key, client_secret=client_secret, callback_uri="oob")
|
oauth = OAuth1Session(client_key, client_secret=client_secret, callback_uri="oob")
|
||||||
fetch_response = oauth.fetch_request_token(request_token_url)
|
fetch_response = oauth.fetch_request_token(request_token_url, headers=headers)
|
||||||
|
|
||||||
session["owner_key"] = fetch_response.get("oauth_token")
|
session["owner_key"] = fetch_response.get("oauth_token")
|
||||||
session["owner_secret"] = fetch_response.get("oauth_token_secret")
|
session["owner_secret"] = fetch_response.get("oauth_token_secret")
|
||||||
|
|
@ -349,6 +351,7 @@ def oauth_callback() -> Response:
|
||||||
client_key = app.config["CLIENT_KEY"]
|
client_key = app.config["CLIENT_KEY"]
|
||||||
client_secret = app.config["CLIENT_SECRET"]
|
client_secret = app.config["CLIENT_SECRET"]
|
||||||
|
|
||||||
|
headers = user_agent_headers()
|
||||||
oauth = OAuth1Session(
|
oauth = OAuth1Session(
|
||||||
client_key,
|
client_key,
|
||||||
client_secret=client_secret,
|
client_secret=client_secret,
|
||||||
|
|
@ -367,7 +370,7 @@ def oauth_callback() -> Response:
|
||||||
verifier=verifier,
|
verifier=verifier,
|
||||||
)
|
)
|
||||||
|
|
||||||
oauth_tokens = oauth.fetch_access_token(access_token_url)
|
oauth_tokens = oauth.fetch_access_token(access_token_url, headers=headers)
|
||||||
session["owner_key"] = oauth_tokens.get("oauth_token")
|
session["owner_key"] = oauth_tokens.get("oauth_token")
|
||||||
session["owner_secret"] = oauth_tokens.get("oauth_token_secret")
|
session["owner_secret"] = oauth_tokens.get("oauth_token_secret")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue