-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
29c46e3
commit 93f4fa2
Showing
7 changed files
with
86 additions
and
10 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 |
---|---|---|
@@ -1,2 +1,78 @@ | ||
# MobileID | ||
Laravel mobile ID authentication | ||
|
||
## Installation | ||
``` | ||
composer require kullar84/mobileid | ||
``` | ||
The package is now installed. If you are using laravel version < 5.5, add the following line in your `config/app.php` providers section: | ||
``` | ||
kullar84\mobileid\MobileIDServiceProvider::class, | ||
``` | ||
|
||
Create new middleware group to Kernel.php | ||
``` | ||
protected $middlewareGroups = [ | ||
'session' => [ | ||
\Illuminate\Session\Middleware\StartSession::class, | ||
], | ||
]; | ||
``` | ||
|
||
Add new routes that uses this middleware | ||
``` | ||
Route::group(['middleware' => 'session'], function () { | ||
Route::post('mlogin', 'AuthController@mlogin')->name('mlogin'); | ||
Route::post('domlogin', 'AuthController@doMLogin')->name('domlogin'); | ||
}); | ||
``` | ||
|
||
Create required methods | ||
``` | ||
use kullar84\mobileid\MobileIDAuthenticate; | ||
protected function mlogin(Request $request) | ||
{ | ||
$this->validate( | ||
$request, [ | ||
'phone' => 'required|numeric|exists:users,phone', | ||
] | ||
); | ||
$phone = $request->input('phone'); | ||
$auth = new MobileIDAuthenticate(); | ||
$response = $auth->startAuth($phone); | ||
return response()->json($response); | ||
} | ||
protected function doMLogin(Request $request) | ||
{ | ||
//https://www.id.ee/?id=36373 | ||
$auth = new MobileIDAuthenticate(); | ||
$response = $auth->checkAuthStatus(); | ||
if ($response->isError()) { | ||
return response()->json(['error' => true, 'message' => $response->error]); | ||
} elseif ($response->isPending()) { | ||
return response()->json(['pending' => true, 'message' => 'Please wait! You will be redirected shortly']); | ||
} elseif ($response->isSuccess()) { | ||
$phone = $request->input('phone'); | ||
$user = User::findUserByPhone($phone); | ||
if ($user !== null) { | ||
$token = $user->createToken('Token')->accessToken; | ||
return $this->respondWithToken($token); | ||
} | ||
} | ||
return response()->json(['message' => 'Unauthorized'], 422); | ||
} | ||
``` |
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
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
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
*/ | ||
|
||
|
||
namespace kullar84\MobileID; | ||
namespace kullar84\mobileid; | ||
|
||
use 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
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
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