I have a client app that uses the Office 365 SharePoint preview API. Recently (as of October 2014), Microsoft published version 1.0 of that API. The authentication steps used with the preview API no longer work with version 1.0.

To demonstrate the problem I have created a short node.js script. The script does the following:


Authorizes by launching a browser. Gives a redirect URL to localhost and launches a server to catch the redirect post-authorization
POST to https://login.windows.net/common/oauth2/token to get an access token
GET to the Office 365 discovery service to get the SharePoint API endpoint
POST to https://login.windows.net/common/oauth2/token with a refresh token to get a new access token
GET to the SharePoint API endpoint to get a list of files


The script can be used with the preview API and version 1.0 of the API. It is able to get a JSON list of files from the preview API, but fails with the following for version 1.0 (on the last call):


{
    "error": {
        "code": "-2147024891, System.UnauthorizedAccessException",
        "message": "Access denied. You do not have permission to perform this action or access this resource."
    }
}


Does anybody see anything wrong with the sequence of calls?

Please take a look at the sample script for more details.


Question: Undefined offset 1
Answer: Your are getting PHP notice because you are trying to access an array index which is not set.

list($var,$value) = explode('=', $line);


The above line explodes the string $line with = and assign 0th value in $var and 1st value in $value. The issue arises when $line contains some string without =.