.Net SDK Access normal users folders and files using JWT, Oauth
Hi community,
I am trying to achieve a simple function using .Net Core 3.1.
I set up my application, jwt, oauth and downloaded authentication json file and run to access other users files and folders. As advised, I enabled the Perform Actions as Users as well as Generate User Access Tokens.
The following is my code:
var adminToken = boxJWT.AdminToken();
var adminClient = boxJWT.AdminClient(adminToken);
var items = adminClient.FoldersManager.GetFolderItemsAsync("0", 500).Result; --> empty.
or
var userToken = boxJWT.UserToken("12345678"); --> Error
//error_description=Cannot obtain token based on the enterprise configuration for your app
I seems that I have to add http header for the user access, but I don't know how to do it.
Please advise.
-
Hi ,
Wen you added the "perform actions as users" and "generate user access token" options to your JWT app, did you also reauthorize the application in the admin console to ensure the changes were applied to the app? Also make sure that "Application Access" setting is set to "Enterprise" if you are trying to access managed users in the overall enterprise. That would be the first thing that I would check.
Next, for sending an as-user header instead of the user access token method, this guide should provide those details.
Hope that helps,
Jon
-
Thank you Jon!
I re-authorized my application. Up to this far, it is all fine.
Then I tried to get BoxClient by
var user_client = new BoxClient(config, session, asUser: '[USER_ID]');
The parameters:
config : no problem, I have configuration read from my appSettings.json.
session: ?
asUser: [USER_ID] -- 9 digit number 2*******7
Here the session I am not quite sure of. This is my question this time.
When I use OAuth2, my system accesses
https://account.box.com/api/oauth2/authorize?client_id=xxxx
to be redirected to the designated url with Authorization Code, where I use
var session = boxClient.Auth.AuthenticateAsync(code).Result;
Do I have to go through the same flow to get the session?
I appreciate you help me.
Please sign in to leave a comment.
Comments
2 comments