jhoneill / MsftGraph

A PowerShell module for interacting with the Microsoft Graph API for Directory, OneNote, OneDrive, Outlook, Planner, Teams and Sharepoint in Office 365 or consumer versions
MIT License
93 stars 12 forks source link

"WARNING: It doesn't look like there was a valid access token" when using Connect-MSGraph #2

Open ghost opened 4 years ago

ghost commented 4 years ago

Receiving the following error when sending Connect-MSGraph -ForceNew:

WARNING: It doesn't look like there was a valid access token.
jhoneill commented 4 years ago

What version of PowerShell are you running on ? I've just checked this with version 5 and version 7 and it appears to working here. If run with no other parameters and you have no window tenant it will attempt to display a logon dialog and this won't work with PowerShell 6, or on Non-windows versions of PowerShell .

jhoneill commented 4 years ago

I've just seen my mail, it would have helped if you'd said there was an error message before the warning. That suggests that for whatever reason it doesn't like the account you're using. I can sign in with both my Azure AD account and my Microsoft-Account so I'm stuck for what to suggest.

To answer your other question Microsoft came out with their own official module for MSGraph shortly after I finished this one, and killed any interest there might have been in it. So I haven't changed anything since August 2019.

ghost commented 4 years ago

Powershell version is 5.1.18362.752

You have the following message:

Write-Host -ForegroundColor Red "Using the default / sample app ID. You should edit the .PSM1 file and either replace the ID with your own, or remove this message"

But there’s no .psm1 file anywhere in your repository.

I updated lines 10 and 11 with my own Client ID and “common” as the Tenant (which is supposed to work with Live IDs).

Now I get this after being prompted for WINDOWS credentials rather than getting the oAuth page on the web:

Invoke-RestMethod : {"error":"invalid_grant","error_description":"AADSTS50034: The user account {EmailHidden} does not exist in the outlook.com directory. To sign into this application, the account must be added to the directory.\r\nTrace ID: 141def9f-f351-4a8e-930e-a49a70e46100\r\nCorrelation ID: 4d946f4d-ff5d-43ce-ba74-db24b6999a86\r\nTimestamp: 2020-04-13 20:56:51Z","error_codes":[50034],"timestamp":"2020-04-13 20:56:51Z","traceid":"141def9f-f351-4a8e-930e-a49a70e46100","correlation id":"4d946f4d-ff5d-43ce-ba74-db24b6999a86","error_uri":"https://login.microsoft.com/error?code=50034"} At C:\Users\stblr\OneDrive\Documents\WindowsPowerShell\Modules\MsftGraph\1.0.1\Graph.ps1:223 char:13

From: jhoneill notifications@github.com Sent: Monday, April 13, 2020 4:43 PM To: jhoneill/MsftGraph MsftGraph@noreply.github.com Cc: Steven Buehler steven@aliveawakened.net; Author author@noreply.github.com Subject: Re: [jhoneill/MsftGraph] "WARNING: It doesn't look like there was a valid access token" when using Connect-MSGraph (#2)

What version of PowerShell are you running on ? I've just checked this with version 5 and version 7 and it appears to working here. If run with no other parameters and you have no window tenant it will attempt to display a logon dialog and this won't work with PowerShell 6, or on Non-windows versions of PowerShell .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/jhoneill/MsftGraph/issues/2#issuecomment-613088235, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AM53USQYVCG2TCANM4K4POLRMN2NHANCNFSM4MHCTARA.

jhoneill commented 4 years ago

Leave the tennant ID blank, otherwise it will assume you want to hand it a credential object and a logon with an azure ID account in that tennant.

The message you emailed me has a link to here https://login.microsoft.com/error?code=50034

Which says

The user that attempted to sign in doesn't exist in this tenant. This can occur because the user mis-typed their username, or isn't in the tenant. An application may have chosen the wrong tenant to sign into, and the currently logged in user was prevented from doing so since they did not exist in your tenant. If this user should be able to log in, add them as a guest. See docs here: https://docs.microsoft.com/azure/active-directory/b2b/add-users-administrator

I can't get a bogus outlook.com account to give that error with the tenant ID left blank.