I'm using the following code (python, but it doesn't really matter, getting the same result with powershell and invoke-webrequest):
from msrestazure.azure_active_directory import UserPassCredentials
username = '%username%'
password = '%password%'
client_id = '{Azure AD Application GUID}'
secret_id = '{Azure AD Application secret}'
credentials = UserPassCredentials(username, password, client_id, secret_id)
this works for users in one tenant, but doesn't work for the users from another tenant with a weird error:
msrest.exceptions.AuthenticationError: , InvalidGrantError: (invalid_grant) AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password
I can login using the portal with the same credentials just fine. The tenant in question is using AAD Sync and SSO, could that interfere?
If yes, how do I obtain tokens for the users in such an Azure AD?