简体   繁体   English

如何在ASP.NET Web应用程序中使用Box API

[英]how to use box api in asp.net web application

I am trying to use box api in an asp.net web application. 我正在尝试在asp.net Web应用程序中使用Box API。

Based on the search there are two options to access box account; 根据搜索,有两个访问邮箱帐户的选项:

  1. By downloading the Box.V2 package using below link containing the required dlls and use that in our application 通过使用包含所需dll的以下链接下载Box.V2软件包,并在我们的应用程序中使用它

  2. By using Box SDK containing code and reference that inside our application. 通过使用包含代码的Box SDK并在我们的应用程序内部进行引用。 Using this approach we can debug the Box.V2 code by adding the project to our solution. 使用这种方法,我们可以通过将项目添加到解决方案中来调试Box.V2代码。

Correct me if I am wrong. 如果我错了,请纠正我。

So, I am trying to implement the second approach. 因此,我正在尝试实施第二种方法。 Can someone help me move forward by specifying the steps to be taken, minimum .net framework requirement, etc. 有人可以通过指定要采取的步骤,.net框架的最低要求等来帮助我前进。

Good question, GitHub samples does not mention about the Web (Asp.Net). 好问题,GitHub示例未提及Web(Asp.Net)。 It's possible and it looks pretty easy to do once you figure out the the way, I have seen some answers for Windows apps trying to manually build the authorization URLs etc, but there is an easier way to do it. 可能的话,一旦您找到方法,它看起来就很容易做到,我已经看到Windows应用程序尝试手动构建授权URL等的一些答案,但是有一种更简单的方法。

Here's how to do it with OAuth, 这是使用OAuth的方法,

  1. Install nuget 安装nuget

PM> Install-Package Box.V2 PM>安装包Box.V2

  1. Get the Authcode (this is what's been missing in most examples) 获取Authcode(这是大多数示例中所缺少的)

     public async Task<ActionResult> Connect() { var clientId = "xxxxx"; var clientSecret = "xxxxxx"; var redirectUri = new Uri("http://localhost:xxxx/Home/AuthCallBackAsync");//Your call back URL var config = new BoxConfig(clientId, clientSecret, redirectUri); return Redirect(config.AuthCodeUri.ToString()); } 

Interesting thing is that the "config" object generates the AuthCodeUri. 有趣的是,“ config”对象生成AuthCodeUri。 This will redirect the user to Consent screen and ask the user to sign in. Once the user "Grants Access" you will get the "Authcode" for your call back URL which can be used to generate accesstoken. 这会将用户重定向到“同意”屏幕,并要求用户登录。一旦用户“授予访问权限”,您将获得用于回叫URL的“ Authcode”,可用于生成访问令牌。

  1. Handle the Auth Callback response 处理Auth回调响应

     public async Task<ActionResult> AuthCallbackAsync() { NameValueCollection parms = Request.QueryString; var authCode = parms["code"] //Get "config" - you can store this in session or in a cache. var config = new BoxConfig(clientId, clientSecret, redirectUri); var client = new BoxClient(config); await client.Auth.AuthenticateAsync(authCode); //Now you will get the accesstoken and refresh token var accessToken = client.Auth.Session.AccessToken; var refreshToken = client.Auth.Session.RefreshToken; //Ready to consume the API var user = await client.UsersManager.GetCurrentUserInformationAsync(); -------More Api Calls--- } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET Web 应用程序消息框 - ASP.NET Web Application Message Box 如何将 AccessTokens 存储到 Cookies 并使用它们为 Asp.net web 应用程序(非 MVC)调用图 API - How Store AccessTokens to Cookies and use them to call Graph API for Asp.net web application (non MVC) 如何在Web API应用程序中使用ASP.net 5 Identity? 基于令牌的用户身份验证。 移动应用 - How to use ASP.net 5 Identity in web API application? User authentication based on tokens. Mobile apps 如何在ASP.NET Web应用程序中使用libphonenumber库? - How to use libphonenumber library in an ASP.NET Web Application? 如何在asp.net Web应用程序的代码背后使用jquery - how to use jquery in the codebehind of asp.net web application 如何在 ASP.NET Razor Web 应用程序中调用 ASP.NET API - How to call an ASP.NET API in an ASP.NET Razor web application 如何在DTO和ASP.NET Web API和Unity中使用接口? - How to use interfaces in DTO with ASP.NET Web API and Unity? 如何在ASP.NET Web API 1.x中使用SupportsCredentials? - how to use SupportsCredentials in asp.net web api 1.x? 如何在ASP.NET Core动态Web API中使用HttpGet? - How to use HttpGet in ASP.NET Core dynamic web api? 如何使用两个asp.net web api的持票令牌 - How to use bearer token with two asp.net web api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM