2

I'm currently trying to achieve in Node.js a direct login to Calendar/Users using Microsoft Graph.

What I've done so far are the following:

  1. Login on the account and make sure that it currently has a calendar (the email is registered under @outlook.com).

  2. Go to azure portal and create a new AAD name "Calendar Api" web API with return URL http://localhost:3000

  3. AAD -> App Registration -> Name: Test, reply url: localhost:3000, Required Permissions for Microsoft Graph (Users Read/Write, Calendars Read/Write), Windows AAD (offline_access), Grant Permissions, Generated a new secret key with no expiry date.

  4. Went to Postman and started to generate a new token based on the following URL:

https://login.microsoftonline.com/{APP_ID_URI}.onmicrosoft.com/oauth2/v2.0/token
  • grant_type : client_credentials
  • client_id : {app_id}
  • client_secret : {app_secret}
  • scope : https://graph.microsoft.com/.default

And I a 200 OK with a token.

  1. Upon inspecting the token:
"aud": "https://graph.microsoft.com",
    "roles": [
        "User.ReadWrite.All",
        "Calendars.Read",
        "Calendars.ReadWrite"
        ],
  1. GET ON -> https://graph.microsoft.com/v1.0/users/ with Authorization Bearer and the above token will return a code status 200 along with the user account I've used in step 1.

  2. GET ON -> https://graph.microsoft.com/v1.0/calendars/ with Authorization Bearer and the above token returns "Resource not found for the segment 'calendars'."

  3. GET ON -> https://graph.microsoft.com/v1.0/users/{user_id}/calendars OR /calendar OR /calendarView:

"code": "OrganizationFromTenantGuidNotFound",
"message": "The tenant for tenant guid '104fdcd9-76d1-4122-89a0-30cb00722de2' does not exist."

I don't really have a code because I am using POSTMAN to test the API first.

I would expect to get a list of events or a list of calendars instead of an error.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
Andrei Stoica
  • 83
  • 1
  • 8

1 Answers1

5

After some digging I found out what the problem was, so here is the full solution to this question.

  1. You need a microsoft office 365 account with subscription, can get this by applying for one on office 365 develop.
  2. Upon creating one, follow the instructions and add the apps to it.
  3. Go to Azure Portal and log in with your office 365 account.
  4. Create an app under AAD -> App registration
  5. Follow step 4 and 5 of this question.
  6. Try to access https://graph.microsoft.com/v1.0/users/{user_id}/calendars.
Andrei Stoica
  • 83
  • 1
  • 8
  • How do you "add the apps to it" exactly? I believe I'm facing the same issue as you did, but I did not understand your steps to solve the problem. If I created an app before this, then I can just leave it and create a new one "under Office 365"? To clarify, I just want to list and update contacts for the users in the organization. – Renato Oliveira Mar 15 '19 at 21:16
  • 1
    By addint the apps to it, i am actuslly reffering during the office 365 dev setup process, after creating a free account you are prompted to add a few microsoft apps to the account such as calendar, mails, contacts etc. And yes, if you already created an app as i have in the question, you can simply leave it or delete it, the new app will be created by the offixe 365 dev account through the azure platform. – Andrei Stoica Mar 18 '19 at 06:35
  • 1
    Im facing the same issue, I created a dev account, however I was never prompt to add any microsoft products, Where can we find the link please? – traveler3468 Aug 16 '19 at 12:38
  • [link](https://account.activedirectory.windowsazure.com/) This should do it – Andrei Stoica Aug 20 '19 at 13:27