-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 29bb3f4
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "stickee/laravel-sftp-dual-auth", | ||
"description": "Stickee Laravel SFTP Dual Auth", | ||
"version": "0.1", | ||
"keywords": [ | ||
"sftp", | ||
"storage" | ||
], | ||
"homepage": "https://www.stickee.co.uk", | ||
"readme": "README.md", | ||
"license": "proprietary", | ||
"autoload": { | ||
"psr-4": { | ||
"Stickee\\LaravelSftpDualAuth\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^7.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Stickee Laravel SFTP Dual Auth | ||
|
||
Provides a dual-authentication filesystem driver for [Laravel](https://laravel.com/). | ||
The built-in sftp driver supports key-based login and password-based login, but not both at the same time. This driver provides that capability. | ||
|
||
## Installation | ||
|
||
Install with composer: | ||
|
||
`composer require stickee/laravel-sftp-dual-auth` | ||
|
||
If you don't use auto-discovery, add the SftpDualAuthServiceProvider to the providers array in *config/app.php* | ||
|
||
``` | ||
Stickee\LaravelSftpDualAuth\SftpDualAuthServiceProvider::class, | ||
``` | ||
|
||
## Usage | ||
|
||
You can noew use *sftp_dual_auth* as a disk driver in *config/filesystems.php* | ||
|
||
``` | ||
'disks' => [ | ||
'local' => [ | ||
'driver' => 'local', | ||
'root' => storage_path('app'), | ||
], | ||
'my_dual_auth' => [ | ||
'driver' => 'sftp_dual_auth', | ||
'host' => env('MY_SFTP_HOST'), | ||
'username' => env('MY_SFTP_USERNAME'), | ||
'password' => env('MY_SFTP_PASSWORD'), | ||
'privateKey' => env('MY_SFTP_PRIVATE_KEY'), | ||
'root' => env('MY_SFTP_ROOT', ''), | ||
], | ||
] | ||
``` | ||
|
||
See the [League Flysystem SFTP documentation](https://flysystem.thephpleague.com/docs/adapter/sftp/) ([GitHub](https://github.com/thephpleague/flysystem-sftp)) for information on the configuration options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Stickee\LaravelSftpDualAuth; | ||
|
||
use Exception; | ||
use League\Flysystem\Sftp\SftpAdapter; | ||
use LogicException; | ||
|
||
/** | ||
* Class SftpDualAuthAdapter | ||
*/ | ||
class SftpDualAuthAdapter extends SftpAdapter | ||
{ | ||
/** | ||
* Login. | ||
* | ||
* @throws Exception | ||
* @throws LogicException | ||
*/ | ||
protected function login() | ||
{ | ||
if ($this->hostFingerprint) { | ||
throw new Exception('Host fingerprint functionality not implemented'); | ||
} | ||
|
||
if (!$this->connection->login($this->getUsername(), $this->getPrivateKey()) | ||
&& !$this->connection->login($this->getUsername(), $this->getPassword())) { | ||
throw new LogicException('Could not login with username: ' . $this->getUsername() . ', host: ' . $this->host); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Stickee\LaravelSftpDualAuth; | ||
|
||
use Illuminate\Filesystem\FilesystemAdapter; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\ServiceProvider; | ||
use League\Flysystem\Filesystem; | ||
use Storage; | ||
|
||
/** | ||
* SftpDualAuthServiceProvider | ||
*/ | ||
class SftpDualAuthServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register any application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
/** | ||
* Create an instance of the sftp dual auth driver. | ||
* | ||
* @param \Illuminate\Foundation\Application $app The app container | ||
* @param array $config The disk configuration | ||
* | ||
* @return \Illuminate\Contracts\Filesystem\Filesystem | ||
*/ | ||
Storage::extend('sftp_dual_auth', function (Application $app, array $config) { | ||
$adapter = new SftpDualAuthAdapter($config); | ||
$filesystem = new Filesystem($adapter, count($config) > 0 ? $config : null); | ||
|
||
return new FilesystemAdapter($filesystem); | ||
}); | ||
} | ||
} |