Skip to content

Commit 24d9fdb

Browse files
authored
Add User-Agent header to OAuth2 token request (#924)
Sets the User-Agent header when fetching the OAuth2 token to ensure proper identification of the client during authentication.
1 parent da13303 commit 24d9fdb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

wikibaseintegrator/wbi_login.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ def __init__(self, consumer_token: Optional[str] = None, consumer_secret: Option
120120

121121
mediawiki_rest_url = str(mediawiki_rest_url or config['MEDIAWIKI_REST_URL'])
122122

123+
headers = {
124+
'User-Agent': get_user_agent(user_agent or (str(config['USER_AGENT']) if config['USER_AGENT'] is not None else None))
125+
}
126+
123127
session = OAuth2Session(client=BackendApplicationClient(client_id=consumer_token))
124128
try:
125-
session.fetch_token(token_url=mediawiki_rest_url + '/oauth2/access_token', client_id=consumer_token, client_secret=consumer_secret)
129+
session.fetch_token(token_url=mediawiki_rest_url + '/oauth2/access_token', client_id=consumer_token, client_secret=consumer_secret, headers=headers)
126130
except InvalidClientError as err:
127131
raise LoginError(err) from err
128132
super().__init__(session=session, token_renew_period=token_renew_period, user_agent=user_agent, mediawiki_api_url=mediawiki_api_url)

0 commit comments

Comments
 (0)