Search code examples
c#dropboxdropbox-apidropnet

Dropnet on MVC after redirect


I have an MVC website in which I am using the DropNet Api.

public ActionResult AuthorizeDropBox()
{
    try
    {
        var _client = new DropNetClient("API KEY", "API SECRET");
        if (_client == null)
            throw new DropboxException();

        var userLogin = _client.GetToken();
        var url = _client.BuildAuthorizeUrl(userLogin, Url.Action("DropBoxCallBack", "Account", null, Request.Url.Scheme));
        return Redirect(url);                
    }

    catch (DropboxException dbe)
    {

    }
}

public ActionResult DropBoxCallBack()
{
    //Not sure here how to access the Dropbox api
    //var fileBytes = _client.GetFile("/Getting Started.pdf");
    return View();
}

So I redirect the user to the Dropbox page that asks the user about allowing my website connect his data and then I DropBoxCallBack is raised.

However I don't have the _client here. But I even tried putting the _client on Session but I still get errors when trying to access Dropbox functionality.

Any help would be appreciated.

Thanks


Solution

  • You were on the right track trying to put the DropNetClient instance in the session. Though you only need to store the userLogin object once you call _client.GetToken() then user that user token and secret to create a new instance of the DropNetClient and finish the authentication process.

    For more info have a look at this answer: https://stackoverflow.com/a/25798991/75946