-
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.
Merge pull request #1 from cyrildewit/release/v0.1.0
Release v0.1.0
- Loading branch information
Showing
10 changed files
with
367 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,2 @@ | ||
vendor/ | ||
composer.lock |
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 @@ | ||
preset: laravel |
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 @@ | ||
language: php | ||
|
||
php: | ||
- 7.1 | ||
- 7.2 | ||
- 7.3 | ||
- nightly | ||
|
||
env: | ||
matrix: | ||
- COMPOSER_FLAGS="--prefer-lowest" | ||
- COMPOSER_FLAGS="" | ||
|
||
matrix: | ||
fast_finish: true | ||
allow_failures: | ||
- php: nightly | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source | ||
|
||
script: | ||
- vendor/bin/phpunit | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
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,14 @@ | ||
# Release Notes | ||
|
||
All notable changes to `Laravel Silent Authentication` will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## [v0.1.0] (2019-02-09) | ||
|
||
### Added | ||
|
||
- Added config file that allows people to customize/disable the default scaffholding | ||
- Added `SessionGuard` that extends the original class but uses the `SilentAuthentication` trait | ||
- Added `SilentAuthentication` trait which will contain the methods to silently authenticate users |
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 |
---|---|---|
@@ -1 +1,91 @@ | ||
# Laravel Silent Authentication | ||
|
||
This Laravel >= 5.5 package allows you to silently authenticate users. | ||
|
||
## Overview | ||
|
||
I created this package for personal usage. It's based on insights from other open source packages and online blog posts. | ||
|
||
## Documentation | ||
|
||
In this documentation, you will find some helpful information about the use of this Laravel package. | ||
|
||
### Table of contents | ||
|
||
1. [Getting Started](#getting-started) | ||
* [Requirements](#requirements) | ||
* [Installation](#installation) | ||
2. [Usage](#usage) | ||
* [Default setup](#default-setup) | ||
* [SilentAuthentication trait](#preparing-your-model) | ||
|
||
## Getting Started | ||
|
||
### Requirements | ||
|
||
This package requires **PHP 7.1+** and **Laravel 5.5+**. | ||
|
||
Lumen is not supported! | ||
|
||
#### Version information | ||
|
||
| Version | Illuminate | Status | PHP Version | | ||
|---------|------------|----------------|-------------| | ||
| 1.0 | 5.5 - 5.7 | Active support | >= 7.1.0 | | ||
|
||
### Installation | ||
|
||
First, you need to install the package via Composer: | ||
|
||
```winbatch | ||
composer require cyrildewit/laravel-silent-authentication | ||
``` | ||
|
||
You can optionally publish the config file with: | ||
|
||
```winbatch | ||
php artisan vendor:publish --provider="CyrildeWit\LaravelSilentAuthentication\SilentAuthenticationServiceProvider" --tag="config" | ||
``` | ||
|
||
#### Register service provider manually | ||
|
||
If you prefer to register packages manually, you can add the following provider to your application's providers list. | ||
|
||
```php | ||
// config/app.php | ||
|
||
'providers' => [ | ||
// ... | ||
CyrildeWit\LaravelSilentAuthentication\SilentAuthenticationServiceProvider::class, | ||
]; | ||
``` | ||
|
||
## Usage | ||
|
||
### Default setup | ||
|
||
This package will overwrite the default `SessionGuard` by default. The customized session guard uses the `SilentAuthentication` trait which will allow you silently authenticate users. | ||
|
||
If you're not interesting in this default or if it's breaking your application, you can disable it in the config file. | ||
|
||
### SilentAuthentication trait | ||
|
||
If you're already overwriting the default `SessionGuard` in your application, you can simply implement the `SilentAuthentication` trait. | ||
|
||
```php | ||
use Illuminate\Auth\SessionGuard as BaseSessionGuard; | ||
use CyrildeWit\LaravelSilentAuthentication\Guards\Traits\SilentAuthentication; | ||
|
||
class SessionGuard extends BaseSessionGuard | ||
{ | ||
use SilentAuthentication; | ||
} | ||
``` | ||
|
||
## Changelog | ||
|
||
Please see [CHANGELOG](CHANGELOG-2.0.md) for more information on what has changed recently. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details. |
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,62 @@ | ||
{ | ||
"name": "cyrildewit/laravel-silent-authentication", | ||
"description": "Silent authentication methods for Laravel", | ||
"type": "library", | ||
"license": "MIT", | ||
"homepage": "https://github.com/cyrildewit/laravel-silent-authentication", | ||
"keywords": [ | ||
"laravel", | ||
"silent", | ||
"authentication", | ||
"login", | ||
"logout", | ||
"no events" | ||
], | ||
"support": { | ||
"email": "github@cyrildewit.nl", | ||
"issues": "https://github.com/cyrildewit/laravel-impersonate/issues", | ||
"wiki": "https://github.com/cyrildewit/laravel-impersonate/wiki", | ||
"source": "https://github.com/cyrildewit/laravel-impersonate", | ||
"docs": "https://github.com/cyrildewit/laravel-impersonate/wiki" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Cyril de Wit", | ||
"email": "info@cyrildewit.nl", | ||
"homepage": "http://cyrildewit.nl", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.1", | ||
"illuminate/auth": "5.5.*|5.6.*|5.7.*" | ||
}, | ||
"require-dev": { | ||
"mockery/mockery": "^1.0", | ||
"orchestra/testbench": "~3.5.0|~3.6.0|~3.7.0", | ||
"phpunit/phpunit": "^6.5|^7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"CyrildeWit\\LaravelSilentAuthentication\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"CyrildeWit\\LaravelSilentAuthentication\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"CyrildeWit\\LaravelSilentAuthentication\\SilentAuthenticationServiceProvider" | ||
] | ||
} | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'default_session_guard' => [ | ||
|
||
'enabled' => true, | ||
'provider_name' => 'session', | ||
|
||
], | ||
|
||
]; |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Laravel Silent Authentication package. | ||
* | ||
* (c) Cyril de Wit <github@cyrildewit.nl> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CyrildeWit\LaravelSilentAuthentication\Guards; | ||
|
||
use Illuminate\Auth\SessionGuard as BaseSessionGuard; | ||
use CyrildeWit\LaravelSilentAuthentication\Guards\Traits\SilentAuthentication; | ||
|
||
class SessionGuard extends BaseSessionGuard | ||
{ | ||
use SilentAuthentication; | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Laravel Silent Authentication package. | ||
* | ||
* (c) Cyril de Wit <github@cyrildewit.nl> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CyrildeWit\LaravelSilentAuthentication\Guards\Traits; | ||
|
||
use Illuminate\Contracts\Auth\Authenticatable; | ||
|
||
trait SilentAuthentication | ||
{ | ||
/** | ||
* Log a user into the application without firing login specific events. | ||
* | ||
* @param \Illuminate\Contracts\Auth\Authenticatable $user | ||
* @return void | ||
*/ | ||
public function silentLogin(Authenticatable $user) | ||
{ | ||
$this->updateSession($user->getAuthIdentifier()); | ||
|
||
$this->setUser($user); | ||
} | ||
|
||
/** | ||
* Log the user out of the application without refreshing the "remember me" | ||
* token and firing logout specific events. | ||
* | ||
* @return void | ||
*/ | ||
public function silentLogout() | ||
{ | ||
$this->clearUserDataFromStorage(); | ||
|
||
$this->user = null; | ||
|
||
$this->loggedOut = true; | ||
} | ||
} |
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,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Eloquent Viewable package. | ||
* | ||
* (c) Cyril de Wit <github@cyrildewit.nl> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CyrildeWit\LaravelSilentAuthentication; | ||
|
||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\ServiceProvider; | ||
use CyrildeWit\LaravelSilentAuthentication\Guards\SessionGuard; | ||
|
||
class SilentAuthenticationServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Perform post-registration booting of services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
if ($this->app->runningInConsole()) { | ||
$config = $this->app->config['silent-authentication']; | ||
|
||
$this->publishes([ | ||
__DIR__.'/../config/silent-authentication.php' => $this->app->configPath('silent-authentication.php'), | ||
], 'config'); | ||
} | ||
} | ||
|
||
/** | ||
* Register bindings in the container. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->mergeConfigFrom( | ||
__DIR__.'/../config/silent-authentication.php', | ||
'silent-authentication' | ||
); | ||
|
||
if (config('silent-authentication.default_session_guard.enabled')) { | ||
$this->registerSessionDriver(); | ||
} | ||
} | ||
|
||
/** | ||
* Register the custom session driver with silent authentication. | ||
* | ||
* @return void | ||
*/ | ||
protected function registerSessionDriver() | ||
{ | ||
$auth = $this->app['auth']; | ||
|
||
$providerName = config('silent-authentication.default_session_guard.provider_name'); | ||
|
||
$auth->extend($providerName, function (Application $app, $name, array $config) use ($auth) { | ||
$provider = $auth->createUserProvider($config['provider']); | ||
|
||
$guard = new SessionGuard($name, $provider, $app['session.store']); | ||
|
||
if (method_exists($guard, 'setCookieJar')) { | ||
$guard->setCookieJar($app['cookie']); | ||
} | ||
|
||
if (method_exists($guard, 'setDispatcher')) { | ||
$guard->setDispatcher($app['events']); | ||
} | ||
|
||
if (method_exists($guard, 'setRequest')) { | ||
$guard->setRequest($app->refresh('request', $guard, 'setRequest')); | ||
} | ||
|
||
return $guard; | ||
}); | ||
} | ||
} |