Change oauth grant type : 'clients_credentials' to 'password'
This commit is contained in:
parent
1a15325bb0
commit
acc90bf905
|
@ -14,7 +14,7 @@ use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
|||
use Laravel\Lumen\Auth\Authorizable;
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use SMartins\PassportMultiauth\HasMultiAuthApiTokens;
|
||||
//use SMartins\PassportMultiauth\HasMultiAuthApiTokens;
|
||||
|
||||
/**
|
||||
* Class User
|
||||
|
@ -39,7 +39,7 @@ use SMartins\PassportMultiauth\HasMultiAuthApiTokens;
|
|||
*/
|
||||
class User extends Model implements AuthenticatableContract, AuthorizableContract
|
||||
{
|
||||
use HasMultiAuthApiTokens, Authenticatable, Authorizable;
|
||||
use HasApiTokens, Authenticatable, Authorizable;
|
||||
|
||||
protected $table = 'users';
|
||||
public $timestamps = false;
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Laravel\Lumen\Auth\Authorizable;
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
//use SMartins\PassportMultiauth\HasMultiAuthApiTokens;
|
||||
|
||||
/**
|
||||
* Class User
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $email
|
||||
* @property string $phone
|
||||
* @property string $encrypted_password
|
||||
* @property string $salt
|
||||
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class UsersCredentials extends Model implements AuthenticatableContract, AuthorizableContract
|
||||
{
|
||||
use HasApiTokens, Authenticatable, Authorizable;
|
||||
|
||||
protected $table = 'users_credentials';
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
protected $hidden = [
|
||||
'encrypted_password'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'email',
|
||||
'phone',
|
||||
'encrypted_password',
|
||||
'salt',
|
||||
];
|
||||
|
||||
/**
|
||||
* Find the user instance for the given username.
|
||||
*
|
||||
* @param string $username
|
||||
* @return \App\Models\User
|
||||
*/
|
||||
public function findForPassport($username)
|
||||
{
|
||||
// return $this->where('phone', $username)->first();
|
||||
// dd($this->where('email', $username)->orWhere('phone', $username)->first());
|
||||
return $this->where('email', $username)->orWhere('phone', $username)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the password of the user for the Passport password grant.
|
||||
*
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
public function validateForPassportPasswordGrant($password)
|
||||
{
|
||||
// return Hash::check($password, $this->password);
|
||||
$encrypted_password = base64_encode(sha1($password . $this->salt, true) . $this->salt);
|
||||
return $this->encrypted_password == $encrypted_password;
|
||||
}
|
||||
|
||||
}
|
|
@ -40,6 +40,8 @@ class AuthServiceProvider extends ServiceProvider
|
|||
|
||||
LumenPassport::routes($this->app->router);
|
||||
|
||||
LumenPassport::allowMultipleTokens();
|
||||
|
||||
// Middleware `oauth.providers` middleware defined on $routeMiddleware above
|
||||
// Route::group(['middleware' => 'oauth.providers'], function () {
|
||||
//// LumenPassport::routes(function ($router) {
|
||||
|
|
|
@ -83,9 +83,9 @@ $app->configure('app');
|
|||
// ]);
|
||||
|
||||
$app->routeMiddleware([
|
||||
// 'auth' => App\Http\Middleware\Authenticate::class,
|
||||
'clients.credentials' => Laravel\Passport\Http\Middleware\
|
||||
CheckClientCredentials::class,
|
||||
'auth' => App\Http\Middleware\Authenticate::class,
|
||||
// 'clients.credentials' => Laravel\Passport\Http\Middleware\
|
||||
// CheckClientCredentials::class,
|
||||
// ** New middleware **
|
||||
// 'auth' => \SMartins\PassportMultiauth\Http\Middleware\MultiAuthenticate::class,
|
||||
// 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "9e7a1979b3fe8cbe7bb0f48938029862",
|
||||
"content-hash": "4b74369ff3d65550f83f77eaa90a3132",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
|
@ -3407,6 +3407,58 @@
|
|||
],
|
||||
"time": "2020-03-22T02:34:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "smartins/passport-multiauth",
|
||||
"version": "v7.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sfelix-martins/passport-multiauth.git",
|
||||
"reference": "f4766428e28abe05cc8307415fa16389c56af965"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sfelix-martins/passport-multiauth/zipball/f4766428e28abe05cc8307415fa16389c56af965",
|
||||
"reference": "f4766428e28abe05cc8307415fa16389c56af965",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"laravel/passport": "^8.0",
|
||||
"php": "^7.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.0",
|
||||
"orchestra/database": "^4.0",
|
||||
"orchestra/testbench": "^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SMartins\\PassportMultiauth\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Samuel Martins",
|
||||
"email": "sfelix_martins@hotmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Add support to multi-auth on Laravel Passport",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"multi-auth",
|
||||
"passport"
|
||||
],
|
||||
"time": "2020-04-03T00:08:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/console",
|
||||
"version": "v5.0.5",
|
||||
|
|
|
@ -14,7 +14,8 @@ return [
|
|||
*/
|
||||
|
||||
'defaults' => [
|
||||
'guard' => env('AUTH_GUARD', 'api'),
|
||||
'guard' => 'api',
|
||||
'passwords' => 'users',
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -35,15 +36,15 @@ return [
|
|||
*/
|
||||
|
||||
'guards' => [
|
||||
'api' => ['driver' => 'passport'],
|
||||
// 'api' => [
|
||||
// 'driver' => 'passport',
|
||||
// 'provider' => 'users',
|
||||
// ],
|
||||
// 'agent' => [
|
||||
// 'driver' => 'passport',
|
||||
// 'provider' => 'agents',
|
||||
// ]
|
||||
// 'api' => ['driver' => 'passport'],
|
||||
'api' => [
|
||||
'driver' => 'passport',
|
||||
'provider' => 'users',
|
||||
],
|
||||
'agent' => [
|
||||
'driver' => 'passport',
|
||||
'provider' => 'agents',
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -66,7 +67,7 @@ return [
|
|||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => \App\Models\User::class
|
||||
'model' => \App\Models\UsersCredentials::class
|
||||
],
|
||||
'agents' => [
|
||||
'driver' => 'eloquent',
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
/**
|
||||
* Routes for MobileBackend
|
||||
*/
|
||||
$router->group(['prefix' => '/mobilebackend/interacted' , 'middleware' => 'clients.credentials'], function () use ($router){
|
||||
$router->group(['prefix' => '/mobilebackend/interacted' , 'middleware' => 'auth:api'], function () use ($router){
|
||||
|
||||
$router->post('LoginAction', 'MobileBackendController@action');
|
||||
$router->post('BalanceAction', 'MobileBackendController@action');
|
||||
|
@ -34,7 +34,10 @@
|
|||
/**
|
||||
* Routes for Wallet Service
|
||||
*/
|
||||
$router->group(['prefix' => '/'.env('WALLET_SERVICE_NAME') ,'middleware' => 'clients.credentials'], function () use ($router){
|
||||
$router->group(['prefix' => '/'.env('WALLET_SERVICE_NAME') ,'middleware' => 'auth:api'], function () use ($router){
|
||||
|
||||
$router->post('/transactions','WalletControllerr@post');
|
||||
$router->post('/virement','WalletController@post');
|
||||
|
||||
// Wallets routes
|
||||
$router->group(['prefix' => '/wallets'] , function () use ($router){
|
||||
|
|
Loading…
Reference in New Issue