简体   繁体   中英

Microsoft Graph API login form for oAuth token needed in Laravel: "The selected user account does not exist in the "Microsoft Services" client"

I want to fetch some tasks in my Office 365 Calendar from my Laravel application. So I must use Microsoft Graph to request Office 365.

Thus, I need to login to Microsoft, then I will be offered the OAuth token. Then I will be able to request Microsoft Graph.

Unexpected behavior : When I call this URL https://login.microsoftonline.com/XYZXYZXYZ/oauth2/v2.0/authorize?state=XYZXYZXYZ&scope=offline_access%20openid%20calendars.readwrite%20contacts.readwrite%20files.readwrite%20mail.readwrite%20mail.send%20tasks.readwrite%20mailboxsettings.readwrite%20user.readwrite&response_type=code&approval_prompt=auto&redirect_uri=https%3A%2F%2Fdomain.com%2Fmsgraph%2Foauth&client_id=XYZXYZXYZ. , it displays the login form. I login using the same Microsoft account than I've created on Microsoft Azure to configure the Graph API access data for my Laravel application. This fails with this error:

Le compte d'utilisateur sélectionné n'existe pas dans le client « Microsoft Services » et ne peut pas accéder à l'application « XYZ » dans ce client. Le compte doit d'abord être ajouté en tant qu'utilisateur externe dans le client. Utilisez un autre compte.

Translated in English:

The selected user account does not exist in the "Microsoft Services" client and cannot access the "XYZ" application in this client. The account must first be added as an external user in the client. Use another account.

What I've read and what I've tried to do:

  1. I've read the Microsoft Laravel Package "Graph" documentation , which tell to create a Laravel route (that finally points to https://login.microsoftonline.com/XYZXYZXYZ/oauth2/v2.0/authorize?state=XYZXYZXYZ&scope=offline_access openid calendars.readwrite contacts.readwrite files.readwrite mail.readwrite mail.send tasks.readwrite mailboxsettings.readwrite user.readwrite&response_type=code&approval_prompt=auto&redirect_uri=https%3A%2F%2Fdomain.com%2Fmsgraph%2Foauth&client_id=XYZXYZXYZ )

  2. Seeing this bug, I made some searches. I've read that the problem could be, eventually, caused by the fact that my Azure Account (which I used to configure the Microsoft Graph API as a Laravel developer and, also, to try to log-in to get the OAuth token as a simple Office 365 user), could be not authorized to log-in. So I've read this doc , which tells to eventually edit the Manifest (accessible in the Microsoft Azure site) by setting this: "signInAudience": "AzureADandPersonalMicrosoftAccount", (or another value among these 3: AzureADMyOrg , AzureADMultipleOrgs , AzureADandPersonalMicrosoftAccount ). However, if I change it, a new problem occurs when trying to login: a problem with the tenant ID...

I don't understand why I can't log-in using my Azure Account. I simply want to be able to get the OAuth token so that my Laravel app will be able to access my Office 365 Tasks and it looks extremely difficult to do it. I think this is a configuration problem. Could you tell me a way to fix this problem?

When you request /authorize endpoint, you will get the code in the url. That returns the blank page in your comment.

在此处输入图像描述

After posting /token to get the access token with authorization code, you could get the access token.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM