When logging into Moodle with a new user coming from Azure, the user name is determined by using a key called 'upn'. This key is not returned by Azure, so function 'handlelogin' falls back to key 'oidcuniqid'.
I figured out, that instead a key 'unique_name' is delivered by Azure. Using that key allows proper authentication flow during REST calls for example.
I'm closing this issue since it has been so many years and the issue doesn't apply any more. There has been many changes over the years to determine the most appropriate token claim to use as Moodle username.
moodle-auth_oidc 3.2.0.1 (2016120501)
I already opened issue https://github.com/Microsoft/moodle-auth_oidc/issues/25 on the project site.
When logging into Moodle with a new user coming from Azure, the user name is determined by using a key called 'upn'. This key is not returned by Azure, so function 'handlelogin' falls back to key 'oidcuniqid'.
I figured out, that instead a key 'unique_name' is delivered by Azure. Using that key allows proper authentication flow during REST calls for example.
It might be possible, that this issue is related to https://github.com/Microsoft/moodle-auth_oidc/issues/12. We also use guest user, that are invited to our Active Directory since we want user from any kind of domain.
I am looking forward to your response and like to contribute if needed!