Skip to content

Commit 393f5b2

Browse files
committed
refactor(nextcloud): Drop use of XML data
1 parent 6ff9435 commit 393f5b2

File tree

4 files changed

+43
-46
lines changed

4 files changed

+43
-46
lines changed

allauth/socialaccount/providers/base/provider.py

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def __str__(self):
317317
"name",
318318
"display_name",
319319
"displayName",
320+
"displayname",
320321
"Display_Name",
321322
"nickname",
322323
],

allauth/socialaccount/providers/nextcloud/provider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def extract_uid(self, data):
2121
def extract_common_fields(self, data):
2222
return dict(
2323
username=data["displayname"],
24-
email=data["email"],
24+
email=data.get("email"),
2525
)
2626

2727
def get_default_scope(self):

allauth/socialaccount/providers/nextcloud/tests.py

+38-40
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,44 @@ def get_login_response_json(self, with_refresh_token=True):
2222
def get_mocked_response(self):
2323
return MockedResponse(
2424
200,
25-
"""<?xml version="1.0"?>
26-
<ocs>
27-
<meta>
28-
<status>ok</status>
29-
<statuscode>100</statuscode>
30-
<message>OK</message>
31-
<totalitems></totalitems>
32-
<itemsperpage></itemsperpage>
33-
</meta>
34-
<data>
35-
<enabled>1</enabled>
36-
<id>batman</id>
37-
<storageLocation>/var/www/html/data/batman</storageLocation>
38-
<lastLogin>1553946472000</lastLogin>
39-
<backend>Database</backend>
40-
<subadmin/>
41-
<quota>
42-
<free>1455417655296</free>
43-
<used>467191265</used>
44-
<total>1455884846561</total>
45-
<relative>0.03</relative>
46-
<quota>-3</quota>
47-
</quota>
48-
<email>[email protected]</email>
49-
<displayname>batman</displayname>
50-
<phone>7351857301</phone>
51-
<address>BatCave, Gotham City</address>
52-
<website>https://batman.org</website>
53-
<twitter>@the_batman</twitter>
54-
<groups>
55-
<element>admin</element>
56-
</groups>
57-
<language>fr</language>
58-
<locale>fr_FR</locale>
59-
<backendCapabilities>
60-
<setDisplayName>1</setDisplayName>
61-
<setPassword>1</setPassword>
62-
</backendCapabilities>
63-
</data>
64-
</ocs>
25+
"""
26+
{
27+
"ocs": {
28+
"meta": {
29+
"status": "ok",
30+
"statuscode": 100,
31+
"message": "OK",
32+
"totalitems": "",
33+
"itemsperpage": ""
34+
},
35+
"data": {
36+
"enabled": true,
37+
"storageLocation": "\\/var\\/www\\/html\\/data\\/pennersr",
38+
"id": "pennersr",
39+
"lastLogin": 1730973409000,
40+
"backend": "Database",
41+
"subadmin": [],
42+
"quota": {
43+
"free": 9159623057408,
44+
"used": 1585107741,
45+
"total": 9161208165149,
46+
"relative": 0.02,
47+
"quota": -3
48+
},
49+
"email": "[email protected]",
50+
"displayname": "pennersr",
51+
"phone": "",
52+
"address": "",
53+
"website": "",
54+
"twitter": "",
55+
"groups": [
56+
"admin"
57+
],
58+
"language": "nl",
59+
"locale": ""
60+
}
61+
}
62+
}
6563
""",
6664
)
6765

allauth/socialaccount/providers/nextcloud/views.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import xml.etree.ElementTree as ET
2-
31
from allauth.core import context
42
from allauth.socialaccount import app_settings
53
from allauth.socialaccount.adapter import get_adapter
@@ -44,11 +42,11 @@ def get_user_info(self, token: SocialToken, user_id):
4442
resp = (
4543
get_adapter()
4644
.get_requests_session()
47-
.get(self.profile_url + user_id, headers=headers)
45+
.get(self.profile_url + user_id, params={"format": "json"}, headers=headers)
4846
)
4947
resp.raise_for_status()
50-
data = ET.fromstring(resp.content.decode())[1]
51-
return {d.tag: d.text.strip() for d in data if d.text is not None}
48+
data = resp.json()["ocs"]["data"]
49+
return data
5250

5351

5452
oauth2_login = OAuth2LoginView.adapter_view(NextCloudOAuth2Adapter)

0 commit comments

Comments
 (0)