1

I need a PHP app to periodically retrieve mails from a Outlook365 account.

I have been succesful following this example but that requires the user to login before the code can do its work. It will redirect to a login screen before the code can retrieve the mails.

The problem is that PHP app should run without user interaction from a scheduled task. So there is no one to do the login.

Then there is this example using the tenant ID which sort of works.

A typical response look like this:

{
  "token_type": "Bearer",
  "expires_in": "3599",
  "ext_expires_in": "0",
  "expires_on": "1481807261",
  "not_before": "1481803361",
  "resource": "https://outlook.office.com",
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dC...."
}

It gets an access token etc, but when using that token for API calls, I get a 401 status code back.

The first examle (using manual login) gives this response:

{
  "token_type": "Bearer",
  "scope": "https://outlook.office.com/mail.read ..."
  "expires_in": "3599",
  "ext_expires_in": "0",
  "expires_on": "1481807261",
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI...."
  "refresh_token": "OAQABAAAAAADRNYRQ3dhRSrm-4K-adpCJeN_lDCf...."
  "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI...."
}

and using that access token for the API calls works.

Note the differences. The tenant based authorization returns no refresh_token and id_token, but I don't know if that has something to do with the problem.

Are there some parameters missing when requesting the tokens in the first example, or is it a matter of some settings in app settings?

0 Answers0