Skip to content

Commit bd25e53

Browse files
committed
fix: add User-Agent header to authentication API calls
This is being done for compatibility with the Wikimedia Foundation User-Agent Policy The policy can be found at: https://foundation.m.wikimedia.org/wiki/Policy:Wikimedia_Foundation_User-Agent_Policy
1 parent ce0ce1c commit bd25e53

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

openedx/features/wikimedia_features/auth_backend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from django.utils.functional import cached_property
3+
from django.conf import settings
34
from social_core.exceptions import AuthException
45
from common.djangoapps.third_party_auth.identityserver3 import IdentityServer3
56

@@ -25,6 +26,15 @@ def _parse_name(self, name):
2526
firstname = firstname if len(firstname)<=30 else firstname[:30]
2627
return fullname, firstname, lastname
2728

29+
def auth_headers(self):
30+
headers = super().auth_headers()
31+
client = getattr(settings, "PLATFORM_NAME", "wikilearn")
32+
site = getattr(settings, "LMS_ROOT_URL", "https://learn.wiki/")
33+
contact_mail = getattr(settings, "CONTACT_EMAIL", "comdevteam@wikimedia.org")
34+
headers['User-Agent'] = f'{client}/0.13 ({site}; {contact_mail})'
35+
36+
return headers
37+
2838
def get_user_details(self, response):
2939
"""
3040
Returns detail about the user account from the service

0 commit comments

Comments
 (0)