11# Dropbox Adapter Plugin
22
33The ** Dropbox Adapter Plugin** provides Dropbox v2 API integration with Winter CMS as a custom filesystem disk driver.
4- This allows limited usage of Dropbox with Laravel's Storage facade— primarily for custom logic and backup tools such as
4+ This allows limited usage of Dropbox with Laravel's Storage facade — primarily for custom logic and backup tools such as
55[ ` NumenCode.SyncOps ` ] ( https://github.com/numencode/wn-syncops-plugin ) .
66
77[ ![ Version] ( https://img.shields.io/github/v/release/numencode/wn-dropboxadapter-plugin?style=flat-square&color=0099FF )] ( https://github.com/numencode/wn-dropboxadapter-plugin/releases )
@@ -21,6 +21,8 @@ Laravel’s filesystem abstraction, especially for automation, remote syncing, a
2121> filesystem for core ` media ` or ` uploads ` disks. This plugin is not intended for direct media asset management,
2222> but rather for use cases like backup transport, cloud storage sync, or custom plugin integration (e.g. [ ` NumenCode.SyncOps ` ] ( https://github.com/numencode/wn-syncops-plugin ) ).
2323
24+ ---
25+
2426## Installation
2527
2628This plugin is available for installation via [ Composer] ( http://getcomposer.org/ ) .
@@ -37,38 +39,123 @@ php artisan winter:up
3739
3840## Requirements
3941
40- * [ Winter CMS] ( https://wintercms.com/ ) version 1.2.7 or newer
41- * PHP 8.0 or later
42- * A Dropbox API access token
42+ - [ Winter CMS] ( https://wintercms.com ) version 1.2.7 or newer
43+ - PHP 8.0 or later
44+ - A Dropbox App (created in the [ Dropbox App Console] ( https://www.dropbox.com/developers/apps ) )
45+ - For ** Refresh Token Flow** : You'll need your ` App key ` and ` App secret ` .
46+ - For ** Temporary Token Flow** : You'll need a manually generated ` Access token ` .
4347
44- ## Configuration
48+ ## Configuration and Authentication
4549
46- 1 . Create a Dropbox App in the [ Dropbox App Console] ( https://www.dropbox.com/developers/apps ) and generate an access token.
47- 2 . Define a new filesystem disk in your ` config/filesystems.php ` file:
48- ``` php
49- 'dropbox' => [
50- 'driver' => 'dropbox',
51- 'authorization_token' => env('DROPBOX_AUTH_TOKEN'),
52- ],
53- ```
54- 3. Add the token to your `.env` file:
50+ This plugin offers two methods for authenticating with the Dropbox API: the ** Refresh Token Flow** (recommended for
51+ production and long-term use) and the ** Temporary Token Flow** (ideal for quick development or testing).
52+ You can switch between these modes in your ` .env ` file.
53+
54+ ### 1. Create a Dropbox App
55+
56+ Regardless of the authentication method, you need to [ create a Dropbox App] ( https://www.dropbox.com/developers/apps ) .
57+
58+ When creating your app:
59+
60+ - Choose ** "Scoped access"** and select the permissions your application needs (e.g.,
61+ ` files.content.write ` , ` files.content.read ` for read/write access).
62+
63+ ### 2. Choose your authentication method
64+
65+ You specify the authentication method in your ` .env ` file using the ` DROPBOX_AUTH_MODE ` variable.
66+ You can choose between ` refresh_token ` and ` temp_token ` modes.
67+
68+ #### a. Refresh Token Flow (recommended for production)
69+
70+ This is the ** secure and persistent** way to authenticate. It uses a long-lived ** refresh token** to automatically
71+ obtain new, short-lived ** access tokens** as needed, eliminating the need for manual intervention when tokens expire.
72+
73+ ###### Setup Steps:
74+
75+ 1 . ** Add Dropbox App credentials to ` .env ` ** :
76+
77+ You'll need your Dropbox ` App key ` and ` App secret ` .
5578 ``` dotenv
56- DROPBOX_AUTH_TOKEN=your_generated_token
79+ DROPBOX_AUTH_MODE=refresh_token
80+ DROPBOX_APP_KEY=
81+ DROPBOX_APP_SECRET=
82+ DROPBOX_REFRESH_TOKEN=
83+ ```
84+
85+ 2. **Generate your refresh token**:
86+
87+ Use the provided console command to go through the OAuth2 authorization process and obtain your refresh token:
88+ ```bash
89+ php artisan dropboxadapter:setup
5790 ```
58- You can now interact with Dropbox programmatically using the Storage facade in Laravel:
59- ```php
60- Storage::disk('dropbox')->put('backups/site.zip', $contents);
91+
92+ Follow the on-screen prompts:
93+ - It will ask for your **Dropbox App key**.
94+ - It will provide a URL to open in your browser. Authorize your app on Dropbox. After authorization, Dropbox will
95+ provide an "authorization code" (often in the URL parameters if no redirect URI is set, or directly on the
96+ success page). Copy this `code`.
97+ - Paste the `authorization code` back into the console.
98+ - Enter your **Dropbox App secret**.
99+ - The command will then exchange this code for a refresh token and display it.
100+
101+ 3. **Update `.env` with refresh token**:
102+
103+ Copy the generated refresh token and add it to your `.env` file.
104+
105+ #### b. Temporary Token Flow (for development/testing only)
106+
107+ This method is quick and easy for **temporary testing**, but the token will **expire after 4 hours** and requires
108+ manual renewal. **Do not use this in production.**
109+
110+ ###### Setup Steps:
111+
112+ 1. **Generate a temporary access token:**
113+
114+ - Go to your [Dropbox App Console](https://www.dropbox.com/developers/apps).
115+ - Navigate to your app's settings.
116+ - Under "OAuth 2", find the "Generated access token" section and click "Generate". Copy this token.
117+
118+ 2. **Add temporary token to `.env`:**
119+
120+ ```dotenv
121+ DROPBOX_AUTH_MODE=temp_token
122+ DROPBOX_TEMP_TOKEN=
61123 ```
62- This is especially useful for custom automation (e.g., deployment scripts or remote backup workflows).
124+
125+ **Important:** If using this mode, the `DROPBOX_APP_KEY`, `DROPBOX_APP_SECRET`,
126+ and `DROPBOX_REFRESH_TOKEN` variables are ignored by the plugin.
127+
128+ ### 3. Define the dropbox disk
129+
130+ Once you have configured your chosen authentication method in `.env`,
131+ define a new filesystem disk in your `config/filesystems.php` file:
132+
133+ ```php
134+ 'dropbox' => [
135+ 'driver' => 'dropbox',
136+ ],
137+ ```
138+
139+ ### 4. Usage with Storage Facade
140+
141+ You can now interact with Dropbox programmatically using the Storage facade in Laravel:
142+
143+ ``` php
144+ Storage::disk('dropbox')->put('backups/site.zip', $contents);
145+ ```
146+
147+ This is especially useful for custom automation (e.g., deployment scripts or remote backup workflows).
63148
64149## Limitations
150+
65151- ** Not compatible with Winter CMS native ` media ` or ` uploads ` disks.**
66152- ** Not suitable for asset serving or file uploading through the CMS backend UI.**
67153
68154Use Dropbox through this plugin ** only for custom filesystem operations** that are manually invoked or triggered
69155via automation (e.g., within the [ ` NumenCode.SyncOps ` ] ( https://github.com/numencode/wn-syncops-plugin ) plugin or similar).
70156
71157## Example Use Case
158+
72159This plugin was created to support [ ` NumenCode.SyncOps ` ] ( https://github.com/numencode/wn-syncops-plugin ) ,
73160a Winter CMS plugin for managing deployments, backups, and environment synchronization. Dropbox serves as a
74161remote storage destination for sync packages or archive backups.
0 commit comments