Repository: ansible/awx

Issue:
Azure AD username mapings
##### ISSUE TYPE
 - Change username mappings for Azure AD configuration

##### SUMMARY
At the moment when configuring Azure AD SSO the username is mapped as NameSurname. It would be nice to be able to change the mapping to a different attribute in Azure AD

Azure AD username mapings
##### ISSUE TYPE
 - Change username mappings for Azure AD configuration

##### SUMMARY
At the moment when configuring Azure AD SSO the username is mapped as NameSurname. It would be nice to be able to change the mapping to a different attribute in Azure AD



Discussion:
I am having the same issue, but I don't think it's mapped to NameSurname, it is mapped to whatever is in your "Name" field with removal of not allowed chars.
https://github.com/python-social-auth/social-core/blob/master/social_core/backends/azuread.py#L68

I think you can set it to be the e-mail through your settings.py . This seems sufficient for my usage, I have not tried it yet though.
https://github.com/ansible/awx/blob/devel/awx/settings/defaults.py#L491

Short follow up: SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL works as expected, username is now the mail address with azure ad.
I am having the same issue, but I don't think it's mapped to NameSurname, it is mapped to whatever is in your "Name" field with removal of not allowed chars.
https://github.com/python-social-auth/social-core/blob/master/social_core/backends/azuread.py#L68

I think you can set it to be the e-mail through your settings.py . This seems sufficient for my usage, I have not tried it yet though.
https://github.com/ansible/awx/blob/devel/awx/settings/defaults.py#L491

Short follow up: SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL works as expected, username is now the mail address with azure ad.

Resolving patch:
diff --git a/awx/sso/conf.py b/awx/sso/conf.py
--- a/awx/sso/conf.py
+++ b/awx/sso/conf.py
@@ -148,6 +148,16 @@ def __call__(self):
     placeholder=['username', 'email'],
 )
 
+register(
+    'SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL',
+    field_class=fields.BooleanField,
+    default=False,
+    label=_('Use Email address for usernames'),
+    help_text=_('Enabling this setting will tell social auth to use the full Email as username instead of the full name'),
+    category=_('Authentication'),
+    category_slug='authentication',
+)
+
 ###############################################################################
 # LDAP AUTHENTICATION SETTINGS
 ###############################################################################


Test patch:
diff --git a/awx/ui/src/screens/Setting/MiscAuthentication/MiscAuthenticationDetail/MiscAuthenticationDetail.test.js b/awx/ui/src/screens/Setting/MiscAuthentication/MiscAuthenticationDetail/MiscAuthenticationDetail.test.js
--- a/awx/ui/src/screens/Setting/MiscAuthentication/MiscAuthenticationDetail/MiscAuthenticationDetail.test.js
+++ b/awx/ui/src/screens/Setting/MiscAuthentication/MiscAuthenticationDetail/MiscAuthenticationDetail.test.js
@@ -40,6 +40,7 @@ describe('<MiscAuthenticationDetail />', () => {
         SOCIAL_AUTH_ORGANIZATION_MAP: {},
         SOCIAL_AUTH_TEAM_MAP: {},
         SOCIAL_AUTH_USER_FIELDS: [],
+        SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL: false,
       },
     });
     await act(async () => {
@@ -79,6 +80,7 @@ describe('<MiscAuthenticationDetail />', () => {
     assertVariableDetail(wrapper, 'Social Auth Organization Map', '{}');
     assertVariableDetail(wrapper, 'Social Auth Team Map', '{}');
     assertVariableDetail(wrapper, 'Social Auth User Fields', '[]');
+    assertDetail(wrapper, 'Use Email address for usernames', 'Off');
     assertDetail(
       wrapper,
       'Allow External Users to Create OAuth2 Tokens',
diff --git a/awx/ui/src/screens/Setting/MiscAuthentication/MiscAuthenticationEdit/MiscAuthenticationEdit.test.js b/awx/ui/src/screens/Setting/MiscAuthentication/MiscAuthenticationEdit/MiscAuthenticationEdit.test.js
--- a/awx/ui/src/screens/Setting/MiscAuthentication/MiscAuthenticationEdit/MiscAuthenticationEdit.test.js
+++ b/awx/ui/src/screens/Setting/MiscAuthentication/MiscAuthenticationEdit/MiscAuthenticationEdit.test.js
@@ -32,6 +32,7 @@ const authenticationData = {
   SOCIAL_AUTH_ORGANIZATION_MAP: null,
   SOCIAL_AUTH_TEAM_MAP: null,
   SOCIAL_AUTH_USER_FIELDS: null,
+  SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL: false,
 };
 
 describe('<MiscAuthenticationEdit />', () => {