box market place app authentication
hi
I am having trouble understanding authentication for my box application that I intend to add in box marketplace.
I understand how to authenticate in Box using OAuth 2.0 with JWT , but if continue with this approach the user himself will need to create a developer app.
I understand this might be basic question but ,
I want to understand how through my app and one time user authentication , I can access user content without requiring user intervention again?
If I go with OAuth 2.0 with JWT , I face this error while trying to authenticate "The grant type is unauthorized for this client_id".
If I go with Standard OAuth 2.0 , I face this error when trying to get folder items from a different user other than admin "The request requires higher privileges than provided by the access token".
Can anyone help me in this regard ?
attaching the test code i am using .
public class BoxController : Controller { private const string BoxClientId = "xxxxxxxxxxxxxxxxxxxxx"; private const string BoxSecret = "xxxxxxxxxxxxxxxxxxxxx"; private const string RedirectUri = "http://localhost:56742/Box/Response/"; private static Tuple BuildConfig() { var config = new BoxConfig(BoxClientId,BoxSecret,new Uri(RedirectUri)); var client = new BoxClient(config); return Tuple.Create(config, client); } public RedirectResult Index() { var config = BuildConfig().Item1; return Redirect(config.AuthCodeUri.ToString()); } public async Task Response() { var client = BuildConfig().Item2; var code = Request.QueryString["code"]; var authsesion = await client.Auth.AuthenticateAsync(code); var accesstoken = authsesion.AccessToken; var refreshtoken = authsesion.RefreshToken; var expiresin = authsesion.ExpiresIn; using (var stream = new FileStream("tax.docx", FileMode.Open)) { var req = new BoxFileRequest() { Name = "boxtax.docx", Parent = new BoxRequestEntity() { Id = "0" } }; var newFile = await client.FilesManager.UploadAsync(req, stream); Console.Out.WriteLine(newFile.Id); } var boxusercollection = await client.UsersManager.GetEnterpriseUsersAsync(null, 0, 500); var userlist = boxusercollection.Entries.ToDictionary(item => item.Id, item => item.Name + ";" + item.Login); // get a boxclient using accesstoken and refresh token for a different user var auth2 = new OAuthSession(accesstoken, refreshtoken, 3600, "bearer"); var config = BuildConfig().Item1; var key = userlist.First().Key; var userClient = new BoxClient(config, auth2, asUser: key); var items = await userClient.FoldersManager.GetFolderItemsAsync("0", 500); var itemList = items.Entries.ToDictionary(item => item.Id, item => item.Name); Console.Out.WriteLine(itemList.ToString()); } }
サインインしてコメントを残してください。
コメント
1件のコメント