Guest User

Untitled

a guest
Jan 2nd, 2018
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. Exception calling "AcquireToken" with "4" argument(s): "AADSTS50001: The application named https://myappwithapi/Login was not found in the tenant named me.onmicrosoft.com.
  2.  
  3. #setup
  4. $TenantName = "mme.onmicrosoft.com"
  5. $clientId = "1950a258-227b-4e31-a9cf-717495945fc2" # Microsoft
  6. $clientId = "03faf8db-..........................." #
  7.  
  8. $username = "me@me.onmicrosoft.com"
  9. $password = Read-Host -AsSecureString -Prompt "Enter Password"
  10.  
  11.  
  12. # add dlls
  13. $adal = "${env:ProgramFiles(x86)}Microsoft SDKsAzurePowerShellServiceManagementAzureServicesMicrosoft.IdentityModel.Clients.ActiveDirectory.dll"
  14. $adalforms = "${env:ProgramFiles(x86)}Microsoft SDKsAzurePowerShellServiceManagementAzureServicesMicrosoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
  15. $adalplatform = "${env:ProgramFiles(x86)}Microsoft SDKsAzurePowerShellServiceManagementAzureServicesMicrosoft.IdentityModel.Clients.ActiveDirectory.platform.dll"
  16. [System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
  17. [System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null
  18. [System.Reflection.Assembly]::LoadFrom($adalplatform) | Out-Null
  19.  
  20.  
  21.  
  22. #prep request
  23. $redirectUri = "urn:ietf:wg:oauth:2.0:oob" # Microsoft
  24. $resourceAppIdURI = "https://graph.windows.net"
  25. $authority = "https://login.windows.net/$TenantName"
  26. $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
  27.  
  28.  
  29. # Get Token prompting for creds
  30. $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Always")
  31. $authResult
  32.  
  33.  
  34. # Get the cred
  35. $cred = New-Object -TypeName 'Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential' -ArgumentList $username, $password
  36. #$cred = New-Object -TypeName 'Microsoft.IdentityModel.Clients.ActiveDirectory.UserPassCredential' -ArgumentList $username, $password
  37. $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $cred)
  38.  
  39. $authResult
Add Comment
Please, Sign In to add comment