https://github.com/egs33/laravel-datastore-auth
Laravel authentication using Google Datastore
https://github.com/egs33/laravel-datastore-auth
cloud-datastore laravel laravel-5-package laravel-6-package laravel-authentication
Last synced: 4 months ago
JSON representation
Laravel authentication using Google Datastore
- Host: GitHub
- URL: https://github.com/egs33/laravel-datastore-auth
- Owner: egs33
- License: mit
- Created: 2018-10-18T09:21:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-16T13:07:10.000Z (over 4 years ago)
- Last Synced: 2024-12-10T23:30:26.833Z (5 months ago)
- Topics: cloud-datastore, laravel, laravel-5-package, laravel-6-package, laravel-authentication
- Language: PHP
- Homepage:
- Size: 82 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Datastore Auth
[Laravel authentication](https://laravel.com/docs/master/authentication) using [Google Datastore](https://cloud.google.com/datastore/docs/)[](https://circleci.com/gh/egs33/laravel-datastore-auth)
[](https://packagist.org/packages/egs33/laravel-datastore-auth)
[](https://packagist.org/packages/egs33/laravel-datastore-auth)
[](https://codecov.io/gh/egs33/laravel-datastore-auth)## Requirements
- Laravel >= 5.5.0
- Composer## Installation
$ composer require egs33/laravel-datastore-auth
$ php artisan vendor:publish --provider="DatastoreAuth\DatastoreAuthServiceProvider"## Quick Start
Set authentication driver to `datastore`.
For example, in `config/auth.php`
```php
'providers' => [
'users' => [
'driver' => 'datastore'
]
],
```Then it can use same as [Laravel authentication](https://laravel.com/docs/5.7/authentication)
## Usage
### Create user
```php
$userConfig = [
'name' => 'hoge',
'email' => '[email protected]',
'password' => 'secret'
];
$userProvider = Auth::createUserProvider('users');
$userProvider->create($userConfig);
// or
DatastoreAuth::create($userConfig);
```### Get Current User etc.
Use `Auth` facade.
Same as [Laravel authentication](https://laravel.com/docs/5.7/authentication)
```php
$user = Auth::user(); // get current user
$isLoggedIn = Auth::check();
```### Update User Data
```php
$user['name'] = 'new-name';
$user['group'] = 'new-group';
$user->save();
```## Config
Config file is `config/datastore_auth.php`
Default is
```php
[
'client_config' => [],
'kind' => 'users',
'cache' => [
'isEnabled' => false,
'keyPrefix' => \DatastoreAuth\DatastoreUserProvider::class . ':',
'ttl' => null,
]
]
````client_config` is passed to constructor of `Google\Cloud\Datastore\DatastoreClient`.
Please see [document](https://googleapis.github.io/google-cloud-php/#/docs/cloud-datastore/v1.7.0/datastore/datastoreclient) of `google/cloud-datastore`.`kind` is kind name of user table.
### Cache
The cache is only used when fetch user by id.
Cache storage is specified by `config/cache.php` in your laravel project.
`ttl` is expressed in seconds regardless of the laravel version.
If it's null, no expire.When `DatastoreUserProvider#resetPassword`, `DatastoreUserProvider#save`, `DatastoreUserProvider#updateRememberToken`
or `User#save` is called, cache is cleared.
But you can call `DatastoreUserProvider#deleteCache` if necessary.