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;
            };
        }
예제 #2
0
 public DropboxDataService(string apiKey, string appSecret, string accessToken)
 {
     _dropNetClient = new DropNetClient(apiKey, appSecret, accessToken, null)
     {
         UseSandbox = true
     };
 }
예제 #3
0
        public async void Authorise()
        {
            _client = _dropboxFactory.Create();
            var authorizeUrl = _client.GetTokenAndBuildUrl("http://www.google.com");

            await LoadBrowserUri(authorizeUrl);
        }
예제 #4
0
        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;
            });
        }
예제 #5
0
        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);
            };
        }
예제 #7
0
 public static void RequiresDropboxAuthentication(this INancyModule module, IDropNetClient dropNetClient)
 {
     module.AddBeforeHookOrExecute(SecurityHooks.RequiresDropboxAuthentication(dropNetClient), "Authentication failed.");
 }
 public async void Authorise()
 {
     _client = _dropboxFactory.Create();
     var authorizeUrl = _client.GetTokenAndBuildUrl("http://www.google.com");
     await LoadBrowserUri(authorizeUrl);
 }