0
votes

I am developing an ios app in objective C for my client. It involves office 365 api usage for onedrive (sharepoint). I am using OfficeDev/Office-365-SDK-for-iOS library from github. azure is setup properly for office 365. App is setup in azure with all permission. However I am not the admin.

With the app I am able to log in to onedrive and can able to fetch the token. With "https://api.office.com/discovery/me/services", I am able to fetch the services. However when I am trying get files with "https://xxx-my.sharepoint.com/_api/v1.0/me/files/root1/", I am getting following error :

Error:

getFiles error: Error Domain=Error in the Request Code=403 "The operation couldn’t be completed. (Error in the Request error 403.)" UserInfo=0x170260980 {error={ code = "-2147024891, System.UnauthorizedAccessException"; message = "Access denied. You do not have permission to perform this action or access this resource."; }}

Could anyone faced this kind of issue..

1

1 Answers

0
votes

The access token which you already have is for service discovery only. You need to get access token for specific service. See https://msdn.microsoft.com/en-us/office/office365/howto/discover-service-endpoints for details.

So, basically you need to perform one more request:

POST https://login.microsoftonline.com/common/oauth2/token 
{
  'grant_type': 'refresh_token',
  'client_id': <your client_id>,
  'client_secret': <your client_secret>,
  'refresh_token': <refresh token that you already have>,
  'resource': <resource_id of resource you want to access>
}

It will return access token which you can use to access specific service API.