title: Accessing Office365 API with Client Credentials Flow
body: <p>I am trying to develop a node application that would be able to access my Outlook.com mails.</p>
  
  <p>I am trying to do it in a way it doens't require me to enter my credentials, the application will know them (user name and password). I am not too worried about storing them in the config of my application.</p>
  
  <p>I am using simple-oauth2 but I keep getting an error. The following is the code that is trying to retrieve the Oauth token:</p>
  
  <pre><code>    const credentials = {
          client: {
              id: this.appId,
              secret: this.appSecret,
          },
          auth: {
              tokenHost: "https://login.microsoftonline.com",
              authorizePath: "common/oauth2/v2.0/authorize",
              tokenPath: "common/oauth2/v2.0/token",
          },
      };
  
      const oathClient = oauth2.create(credentials);
      const tokenConfig =  {
          username: "zzz@outlook.com",
          password: "xxxxx",
          scope: "Mail.Read",
      };
  
      const result = await oathClient.ownerPassword.getToken(tokenConfig);
      const token = oathClient.accessToken.create(result);
  </code></pre>
  
  <p>However when calling get token I get the following response:</p>
  
  <pre><code>   "error": "invalid_grant",
      "error_description": "AADSTS70000: The grant is not supported by this API version\r\nTrace ID: 91935472-5d7b-4210-9a56-341fbda12a00\r\nCorrelation ID: 6b075f4e-b649-493e-a87b-c74f0e427b47\r\nTimestamp: 2017-08-19 14:00:33Z",
      "error_codes": [ 70000],
  </code></pre>
  
  <p>I have aded the application in apps.dev.microsoft.com</p>
  
  <p>Added a platform (Web API) for it.
  Added the "Mail.Read" permission on Microsoft Grah</p>
  
  <p>And I am using the apikey and secret I generated there.</p>
  
  <p>Googling looks like all the examples I find are to connect is using a client certificate. Is it possible to use the API using the API credentials?</p>
  
  <p>If the only way is using certificates, is there a way I can use simple-oauth2 for that?</p>