Skip to content

Commit 1deb52e

Browse files
committed
add weixin PSA
1 parent 1cc90ac commit 1deb52e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/galaxy/authnz/psa_authnz.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"egi_checkin": "social_core.backends.egi_checkin.EGICheckinOpenIdConnect",
5353
"oidc": "social_core.backends.open_id_connect.OpenIdConnectAuth",
5454
"tapis": "galaxy.authnz.tapis.TapisOAuth2",
55+
"weixin": "galaxy.authnz.weixin.WeixinAuth2",
5556
}
5657

5758
BACKENDS_NAME = {
@@ -66,6 +67,7 @@
6667
"egi_checkin": "egi-checkin",
6768
"oidc": "oidc",
6869
"tapis": "tapis",
70+
"weixin": "weixin",
6971
}
7072

7173
AUTH_PIPELINE = (

lib/galaxy/authnz/weixin.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import re
2+
from social_core.backends.weixin import WeixinOAuth2
3+
4+
class WeixinAuth2(WeixinOAuth2):
5+
name = 'weixin'
6+
7+
def user_data(self, access_token, *args, **kwargs):
8+
data = super().user_data(access_token, *args, **kwargs)
9+
if not data.get('id_token'):
10+
data['id_token'] = "dummy"
11+
return data
12+
13+
def get_user_id(self, details, response):
14+
uid = response.get('unionid') or response.get('openid')
15+
return uid.lower()
16+
17+
def get_user_details(self, response):
18+
data = super().get_user_details(response)
19+
uid = self.get_user_id({}, response)
20+
if not uid:
21+
return data
22+
username = re.sub(r'[^a-z0-9_]', '_', uid.lower())
23+
data['username'] = username
24+
if not data.get('email') and username:
25+
data['email'] = f"{username}@dummy.com"
26+
return data

0 commit comments

Comments
 (0)