Search code examples
office365office365apioffice365-appsoffice365-restapioffice365connectors

Office365 API: The token has an invalid signature


I'm currently trying to query the Office365 API from a php back end using an access token acquired from the front end via adaljs. API calls from the front end work perfectly. However, api calls using the same token from the back end and Postman fail with the error: 2000000;reason="The token has an invalid signature.";error_category="invalid_signature"

Front end (working) example:

$http.get("https://outlook.office365.com/api/v1.0/me/calendarview?StartDateTime=2016-08-02T00:00:00Z&EndDateTime=2016-08-02T23:59:00Z") //working
            .then(function (response) {
                $log.debug('HTTP request to Calendar API returned successfully.');
                console.log(response);
            }, function (error) {
                $log.error('HTTP request to Calendar API failed.');
                console.log(error);
            });

Acquire the token for the Office365 API (not my client app) and store in db:

adalAuthenticationService.acquireToken('https://outlook.office365.com').then(function(refreshToken) {

            var data = {

                code: refreshToken,
                email: email

            };

            console.log(refreshToken);

            Office365.createIntegration('office365', data)

                .then(function() {

                    console.log("link created");
                    $scope.loading = false;


                }, function(error) {

                    console.error(error);
                    $scope.loading = false;

                })

        }, function(err) {

            console.error(err);

        });

JWT has aud: "https://outlook.office365.com", set properly too


Solution

  • I feel really silly, but my access token wasn't being updated in some other code to the database (it looked like it, but it wasn't). So the access tokens were invalid, hence the error. If you're seeing this, make sure your access token is valid/the most recent token!