Skip to content
Snippets Groups Projects
Commit 6d0402aa authored by Jean-Philippe Laverdure's avatar Jean-Philippe Laverdure
Browse files

Merge branch '111-oauth' into 'master'

Fetch and set samaccountname

See merge request !56
parents c4357734 9d8ed679
No related branches found
No related tags found
1 merge request!56Fetch and set samaccountname
...@@ -153,6 +153,7 @@ SOCIAL_AUTH_PIPELINE = ( ...@@ -153,6 +153,7 @@ SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.associate_user', 'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data', 'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details', 'social_core.pipeline.user.user_details',
# 'social_core.pipeline.debug.debug'
) )
SOCIAL_AUTH_URL_NAMESPACE = 'social' SOCIAL_AUTH_URL_NAMESPACE = 'social'
......
...@@ -14,11 +14,16 @@ class LoginSuccess(View): ...@@ -14,11 +14,16 @@ class LoginSuccess(View):
""" """
user = self.request.user user = self.request.user
azuread_groups = None azuread_data = {}
try: try:
azuread_groups = user.social_auth.get(provider='azuread-tenant-oauth2').extra_data['groups'] azuread_data = user.social_auth.get(provider='azuread-tenant-oauth2').extra_data
except: except:
pass pass
azuread_groups = azuread_data['groups'] if 'groups' in azuread_data else None
azuread_samaccountname = azuread_data['onPremisesSamAccountName'] if 'onPremisesSamAccountName' in azuread_data else None
if azuread_samaccountname and not user.profile.accountname:
user.profile.accountname = azuread_samaccountname
if hasattr(user, 'ldapuser') or azuread_groups: if hasattr(user, 'ldapuser') or azuread_groups:
user.profile.labs.remove(*Lab.objects.filter(ldap__startswith='iric-')) user.profile.labs.remove(*Lab.objects.filter(ldap__startswith='iric-'))
...@@ -42,4 +47,6 @@ class LoginSuccess(View): ...@@ -42,4 +47,6 @@ class LoginSuccess(View):
request.session['active_lab_id'] = user.profile.labs.first().id request.session['active_lab_id'] = user.profile.labs.first().id
# return redirect('dashboard') # return redirect('dashboard')
user.profile.save()
return redirect('dashboard') return redirect('dashboard')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment