C# How to get collaborators for folders in Box

Highlighted
Occasional Contributor

C# How to get collaborators for folders in Box

Hello,

today i tried to use Box SDK for .NET C#, Box.V2.Core, but i have problem with getting any response from API. Everytime i tried to run or debug program, i get exception Box.V2.Exceptions.BoxSessionInvalidatedException. What cause this exception and how can i fix this? Folder ID is custom, i'm jus ttrying to authenticate and get a response in any way to see if it works. Later i need to make a program to get folders and get collaborators for each folder in box.

 

Code is below (of course client id, secret and developer token is replaced by strings):

 

 

static async System.Threading.Tasks.Task Main(string[] args)
        {
            var config = new BoxConfig("clientid", "clientsecret", new Uri("https://app.box.com"));
            var session = new OAuthSession("developertoken", "N/A", 3600, "bearer");
            var client = new BoxClient(config, session);

            string folderId = "11111";
            BoxCollection<BoxCollaboration> collaborations = await client.FoldersManager.GetCollaborationsAsync(folderId);
        }

 

 Thank you for help. 

Tags (2)
3 REPLIES 3
Highlighted
Box Employee

Re: C# How to get collaborators for folders in Box

Hi @BAILANDO,

 

I think this might have to do with the use of a developer token. The invalid session error will come back once the token has expired, and for a developer token that is 1 hour after it was generated. 

 

I'd suggest using the JWT auth flow or OAuth 2 flow, depending on the type of application that you're trying to build.

 

Hope that helps,

Jon

Highlighted
Occasional Contributor

Re: C# How to get collaborators for folders in Box

Hi,

i wrote a code which's working. But when i want to list folders in my personal box via app, then i need to use developer token. Because when i use oauth JWT authentication, then my app showing empty box root folder and when i create folder via api, then i can see folder only in C# program when i list all folders from root, but not in my personal box account.

 

It's possible to access my personal box folders with JWT app in C#?

 

Thank you

Highlighted
Box Employee

Re: C# How to get collaborators for folders in Box

@BAILANDO The developer token is associated with the user who clicks the button in the developer console to generate the token. However, JWT apps use a token associated with the applications service account by default. You're only going to be able to successfully interact with the content the user associated with the token either owns or has collaborator access to, just like in box.com directly. 

 

If you'd like to obtain a token for your user instead of the service account you need to do this in the JWT assertion. You'll pass your user ID into the sub claim: https://developer.box.com/guides/authentication/jwt/without-sdk/#3.-Create-JWT-assertion

 

Best, 

Kourtney

Box Technical Support Engineer