1. Go to this page and download the library: Download zanderwar/lumen-dropbox library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zanderwar / lumen-dropbox example snippets
return [
/*
* set the client id
*/
'clientId' => env('DROPBOX_CLIENT_ID'),
/*
* set the client secret
*/
'clientSecret' => env('DROPBOX_SECRET_ID'),
/*
* Set the url to trigger the oauth process this url should call return Dropbox::connect();
*/
'redirectUri' => env('DROPBOX_OAUTH_URL'),
/*
* Set the url to redirecto once authenticated;
*/
'landingUri' => env('DROPBOX_LANDING_URL', '/'),
/**
* Set access token, when set will bypass the oauth2 process
*/
'accessToken' => env('DROPBOX_ACCESS_TOKEN', ''),
/**
* Set access type, options are offline and online
* Offline - will return a short-lived access_token and a long-lived refresh_token that can be used to request a new short-lived access token as long as a user's approval remains valid.
*
* Online - will return a short-lived access_token
*/
'accessType' => env('DROPBOX_ACCESS_TYPE', 'offline'),
/*
set the scopes to be used
*/
'scopes' => 'account_info.read files.metadata.write files.metadata.read files.content.write files.content.read',
];
$router->group([/** Middleware etc */], function(\Laravel\Lumen\Routing\Router $router) {
$router->get('/dropbox/connect', function() {
if (! request()->has('code')) {
// user is heading to dropbox
$arbitraryData = ['hello' => 'world'];
return \Zanderwar\Dropbox\Dropbox::connect(json_encode($arbitraryData));
}
// user is returning from dropbox
$state = request()->input('state');
if (! $state) {
throw new \RuntimeException('The state parameter is missing from the request.');
}
// do stuff with $state...
// e.g. Passport::actingAs(Decrypt::json($state)->user_id)
// finalise the account internally, by calling the connect method again. This will fetch
// an access/refresh token from dropbox. This behaviour is only exhibited when the `code`
// query param is in the URL.
return \Zanderwar\Dropbox\Dropbox::connect();
});
$router->get('/dropbox/disconnect', function() {
return Dropbox::disconnect('path/to/redirect/to');
});
});