OfficeDev / Office-365-SDK-for-iOS

Microsoft Services SDKs for iOS Preview produced by MS Open Tech.
https://dev.office.com/
Other
96 stars 49 forks source link

Lists SDK #40

Closed karlbarek closed 9 years ago

karlbarek commented 9 years ago

Has the List portion of the sdk been completed? I'm trying to get Lists working and it's not allowing me to create a ListClient object.

dorinsimina commented 9 years ago

Is there any example of how to use the Lists SDK because the references from http://dev.office.com/ios does not seem to be valid? ... at least the entry point and from there specific operation calls

anihojnadel commented 9 years ago

We started adding those samples to use as a guide. I'll let you know once they're ready (I hope to have them ready for tomorrow EOD).

anihojnadel commented 9 years ago

I've created a new branch with some WIP tests, you can see the code here (you'll need to update with your info to make them work, see BaseController -> getListClient method).

This is how you create a new list client and get the available lists:

OAuthentication *credentials = [[OAuthentication alloc] initWith:token];
ListClient *client = [[ListClient alloc] 
initWithUrl:@"https://yoursharepoint-my.sharepoint.com/personal/user_contoso_com" 
credentials:credentials];

[client getLists:^(NSMutableArray *lists, NSError *error) {
      //your code 
    }]

Let us know if this worked for you.

dorinsimina commented 9 years ago

Yes, it works. Thanks.

dorinsimina commented 9 years ago

It is possible to get access to an image resource parsed between the list items?

Using SDWebImage I tried to prepare such a request, but it returned me 403. After that I tried to set the Authorisation header and now I get 401.

SDWebImageDownloader *manager = [SDWebImageManager sharedManager].imageDownloader;

NSString *authHeader = [NSString stringWithFormat:@"Bearer %@", self.token];

[manager setValue:authHeader forHTTPHeaderField:@"Authorization"];

karlbarek commented 9 years ago

In regards to the 401. We have seen that when trying to access resources such as images. For example, to open a document from SharePoint inside our mobile app it won't launch the interactive preview in an internal WebView or external browser without having the user re-authenticate . The SharePoint oAuth token created from ADAL doesn't work.

dorinsimina commented 9 years ago

For the moment I've created a custom Web API deployed on Azure servers which returns me the image. So from my app I'm passing to the service the image path and I get the image stream.

karlbarek commented 9 years ago

Dorinsimina, Would you be willing to share that Web API code?

dorinsimina commented 9 years ago

Yes, tomorrow I will post it since I still have to make some changes. Anyway I'm not a C# expert so the coding could be better I guess, but it works. The concept could be extended to get any resource not only an image (e.g. a document). There's a getFile method that does the trick..

anihojnadel commented 9 years ago

@dorinsimina I didn't understand what you're trying to do. The auth header is handled by our SDK. Do you have more input?

dorinsimina commented 9 years ago

After parsing the items for a specific list I wanted to get an image resource. For example for my 'Social' list I get all the items and each item could have a picture url.

The picture URL has the following format: https://TENANT.sharepoint.com/PATH.png

I've tried to get the image without/with setting the authorisation header but it constantly fails. In order to fix the issue I've created a custom Web Api on my azure servers to retrieve the image.

anihojnadel commented 9 years ago

@dorinsimina This is something we already implemented for the Android SDK, but we're still in progress for iOS. If you need that feature right now, you can take a look to the DocLibClient to see what we did for the Android platform.

cjgehinscott commented 9 years ago

@anihojnadel I have tried using the DocLibClient on the Android side, as I am building an app that is working with Sharepoint in Android, and I still get a 401 unauthorized. What @dorinsimina is trying to get across is that the access token that is being passed in the authorization header is not being accepted hence the 401. It has nothing to do with the implementation on the client/application side; if it was a bad request we wouldn't get a 401 we would get something in 500s. This is why @dorinsimina, I'm assuming, built a web service that can access those resources to pass down to the app/client that can't access them. My guess is that there is something on the back end with those resources needing to be set up to accept an access token that is created in Azure for a mobile application.

ravidixit commented 9 years ago

@anihojnadel I was looking for List implementation for iOS and came across this thread, got some valuable inputs and tried your WIP test implementation using the ADAL token which we get when we login but am not able to get any response.

Can you help us in resolving this with an example something similar to the one in example folder or some resource online which could guide us out.

dorinsimina commented 9 years ago

You can use the following sample:

OAuthentication credentials = [[OAuthentication alloc] initWith:token]; ListClient clientList = [[ListClient alloc] initWithUrl:@"https://TENANT-my.sharepoint.com/personal/USER/" credentials:credentials];

clientList getLists:^(NSMutableArray lists, NSError error) ...

ravidixit commented 9 years ago

@dorinsimina : what's the token variable here is it the same one which we get when we login or something else? I tried with the ADAL token which we get when we login but it failed

dorinsimina commented 9 years ago

The token variable is the one obtained by granting access to the resource https://TENANT-my.sharepoint.com

ravidixit commented 9 years ago

@dorinsimina Here's the code that i am trying

NSString *appToken = [[NSUserDefaults standardUserDefaults] valueForKey:@"loginToken"];
NSString* hostName = @"https://TENANT-my.sharepoint.com/personal/USER";

OAuthentication *credentials = [[OAuthentication alloc] initWith:appToken];
ListClient *client = [[ListClient alloc]
                      initWithUrl:hostName
                      credentials:credentials];

NSURLSessionTask* task =  [client getLists:^(NSMutableArray *lists, NSError *error) {
    if (error==nil) {
        NSLog(@"%@",lists);
    }
}];

[task resume];

The lists array is always empty, I even replaced the USER with my name but still it's empty. I am trying to fetch the announcements list and few custom list from the tenant not sure where I am wrong.

dorinsimina commented 9 years ago

For example if the tenant is 'test' and the user is 'john.doe@test.onmicrosoft.com' the resource link could be the following: https://test-my.sharepoint.com/personal/john_doe_test_onmicrosoft_com/

Also make sure that your Office 365 native application has granted the access for SharePoint online files access.

Or any other format like (it depends from where you want to extract the lists): https://TENANT-public.sharepoint.com/_api/web/lists

Check it first in you browser to see if it returns data.

ravidixit commented 9 years ago

@dorinsimina : did what you suggested but still no luck maybe my token is wrong, I am passing the token as the one which I get after login.

I have tested the same code in the browser in the browser it works since I am already logged in with my credentials, also i have checked the Office 365 sharepoint online permissions i have full control to all site collection.

I have opened up a issue on a new thread where i have detailed on what i am doing maybe you guys can help me out on that

https://github.com/OfficeDev/Office-365-SDK-for-iOS/issues/52

ZuzooVn commented 9 years ago
initWithUrl:@"https://yoursharepoint-my.sharepoint.com/personal/user_contoso_com" 
credentials:credentials];

How can I automatically get this link for each account without hardcode data?

Thanks

anihojnadel commented 9 years ago

@ZuzooVn You can do that by using the Directory SDK.

https://github.com/OfficeDev/Office-365-SDK-for-iOS/issues/86#issuecomment-140737454