public static Func<NancyContext, Response> RequiresDropboxAuthentication(IDropNetClient dropNetClient) { return (ctx) => { Response response = null; try { var token = dropNetClient.GetAccessToken(); dropNetClient.UserLogin = token; } catch (DropboxRestException ex) when (ex.StatusCode.Equals(System.Net.HttpStatusCode.BadRequest)) { response = new Response { StatusCode = HttpStatusCode.Unauthorized }; } catch (DropboxRestException ex) when (ex.StatusCode.Equals(System.Net.HttpStatusCode.Unauthorized)) { // } return response; }; }
public DropboxDataService(string apiKey, string appSecret, string accessToken) { _dropNetClient = new DropNetClient(apiKey, appSecret, accessToken, null) { UseSandbox = true }; }
public async void Authorise() { _client = _dropboxFactory.Create(); var authorizeUrl = _client.GetTokenAndBuildUrl("http://www.google.com"); await LoadBrowserUri(authorizeUrl); }
public static Func <NancyContext, Response> RequiresDropboxAuthentication(IDropNetClient dropNetClient) { return((ctx) => { Response response = null; try { var token = dropNetClient.GetAccessToken(); dropNetClient.UserLogin = token; } catch (DropboxRestException ex) when(ex.StatusCode.Equals(System.Net.HttpStatusCode.BadRequest)) { response = new Response { StatusCode = HttpStatusCode.Unauthorized }; } catch (DropboxRestException ex) when(ex.StatusCode.Equals(System.Net.HttpStatusCode.Unauthorized)) { // } return response; }); }
public DropboxModule(IDropNetClient dropNetClient) { Get["/files"] = _ => { this.RequiresDropboxAuthentication(dropNetClient); var metaData = dropNetClient.GetMetaData(list: true); return(Response.AsJson(metaData.Contents .Select(f => new { Name = f.Name, Modified = f.Modified, Type = f.Is_Dir ? "Folder": "File" }))); }; Post["/files"] = _ => { var file = Request.Files.FirstOrDefault(); if (file != null) { var uploaded = dropNetClient.UploadFile("/", file.Name, ReadFile(file.Value)); return(uploaded != null ? HttpStatusCode.OK : HttpStatusCode.InternalServerError); } else { return(HttpStatusCode.BadRequest); } }; Get["/login"] = _ => { dropNetClient.GetToken(); var url = dropNetClient.BuildAuthorizeUrl(); return(Response.AsRedirect(url, Responses.RedirectResponse.RedirectType.Permanent)); }; }
public DropboxModule(IDropNetClient dropNetClient) { Get["/files"] = _ => { this.RequiresDropboxAuthentication(dropNetClient); var metaData = dropNetClient.GetMetaData(list: true); return Response.AsJson(metaData.Contents .Select(f => new { Name = f.Name, Modified = f.Modified, Type = f.Is_Dir ? "Folder": "File" })); }; Post["/files"] = _ => { var file = Request.Files.FirstOrDefault(); if (file != null) { var uploaded = dropNetClient.UploadFile("/", file.Name, ReadFile(file.Value)); return uploaded != null ? HttpStatusCode.OK : HttpStatusCode.InternalServerError; } else { return HttpStatusCode.BadRequest; } }; Get["/login"] = _ => { dropNetClient.GetToken(); var url = dropNetClient.BuildAuthorizeUrl(); return Response.AsRedirect(url, Responses.RedirectResponse.RedirectType.Permanent); }; }
public static void RequiresDropboxAuthentication(this INancyModule module, IDropNetClient dropNetClient) { module.AddBeforeHookOrExecute(SecurityHooks.RequiresDropboxAuthentication(dropNetClient), "Authentication failed."); }