Skip to content

Commit

Permalink
Merge pull request #216 from yajra/oracle-user-provider
Browse files Browse the repository at this point in the history
[5.3] Implement oracle user provider.
  • Loading branch information
yajra committed Oct 12, 2016
2 parents 3c79dbb + e5c9fff commit 4ca8c46
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -68,6 +68,19 @@ This will copy the configuration file to `config/oracle.php`.

And run your laravel installation...

## [Laravel 5.2++] Oracle User Provider
When using oracle, we may encounter a problem on authentication because oracle queries are case sensitive by default.
By using this oracle user provider, we will now be able to avoid user issues when logging in and doing a forgot password failure because of case sensitive search.

To use, just update `auth.php` config and set the driver to `oracle`
```php
'providers' => [
'users' => [
'driver' => 'oracle',
'model' => App\User::class,
],
]
```

## Credits

Expand Down
35 changes: 35 additions & 0 deletions src/Oci8/Auth/OracleUserProvider.php
@@ -0,0 +1,35 @@
<?php

namespace Yajra\Oci8\Auth;

use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Support\Str;

class OracleUserProvider extends EloquentUserProvider
{
/**
* Retrieve a user by the given credentials.
*
* @param array $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
{
if (empty($credentials)) {
return;
}

// First we will add each credential element to the query as a where clause.
// Then we can execute the query and, if we found a user, return it in a
// Eloquent User "model" that will be utilized by the Guard instances.
$query = $this->createModel()->newQuery();

foreach ($credentials as $key => $value) {
if (! Str::contains($key, 'password')) {
$query->whereRaw("upper({$key}) = upper(?)", [$value]);
}
}

return $query->first();
}
}
6 changes: 6 additions & 0 deletions src/Oci8/Oci8ServiceProvider.php
Expand Up @@ -3,7 +3,9 @@
namespace Yajra\Oci8;

use Illuminate\Support\ServiceProvider;
use Yajra\Oci8\Auth\OracleUserProvider;
use Yajra\Oci8\Connectors\OracleConnector as Connector;
use Illuminate\Support\Facades\Auth;

class Oci8ServiceProvider extends ServiceProvider
{
Expand All @@ -22,6 +24,10 @@ public function boot()
$this->publishes([
__DIR__ . '/../config/oracle.php' => config_path('oracle.php'),
], 'oracle');

Auth::provider('oracle', function ($app, array $config) {
return new OracleUserProvider($app['hash'], $config['model']);
});
}

/**
Expand Down

0 comments on commit 4ca8c46

Please sign in to comment.