diff --git a/README.md b/README.md index 48951dd..635f295 100644 --- a/README.md +++ b/README.md @@ -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); +} + +``` \ No newline at end of file diff --git a/composer.json b/composer.json index 9620a62..6417d28 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "kullar84/mobile-id", + "name": "kullar84/mobileid", "description": "Estonian MobileID identity provider for laravel", "keywords": ["MobileID", "identity", "auth", "digidocservice","MobiilID","laravel"], "type": "package", @@ -17,16 +17,16 @@ }, "autoload": { "psr-4": { - "kullar84\\MobileID\\": "src/" + "kullar84\\mobileid\\": "src/" } }, "extra": { "laravel": { "providers": [ - "kullar84\\MobileID\\MobileIDServiceProvider" + "kullar84\\mobileid\\MobileIDServiceProvider" ], "aliases": { - "MobileID": "kullar84\\MobileID\\MobileIDFacade" + "MobileID": "kullar84\\mobileid\\MobileIDFacade" } } } diff --git a/src/AuthenticateResponse.php b/src/AuthenticateResponse.php index 8ce736d..a11b5a0 100644 --- a/src/AuthenticateResponse.php +++ b/src/AuthenticateResponse.php @@ -4,7 +4,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace kullar84\MobileID; +namespace kullar84\mobileid; /** * Mobile ID authentication response diff --git a/src/MobileIDAuthenticate.php b/src/MobileIDAuthenticate.php index d107f74..94517d4 100644 --- a/src/MobileIDAuthenticate.php +++ b/src/MobileIDAuthenticate.php @@ -5,7 +5,7 @@ */ -namespace kullar84\MobileID; +namespace kullar84\mobileid; use Session; diff --git a/src/MobileIDException.php b/src/MobileIDException.php index c51fa96..ae696ce 100644 --- a/src/MobileIDException.php +++ b/src/MobileIDException.php @@ -4,7 +4,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace kullar84\MobileID; +namespace kullar84\mobileid; use Exception; diff --git a/src/MobileIDFacade.php b/src/MobileIDFacade.php index e6f716f..84aea99 100644 --- a/src/MobileIDFacade.php +++ b/src/MobileIDFacade.php @@ -4,7 +4,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace kullar84\MobileID; +namespace kullar84\mobileid; use \Illuminate\Support\Facades\Facade; @@ -25,6 +25,6 @@ class MobileIDFacade extends Facade */ protected static function getFacadeAccessor() { - return 'MobileID'; + return 'mobileid'; } } \ No newline at end of file diff --git a/src/MobileIDServiceProvider.php b/src/MobileIDServiceProvider.php index af77939..c23a070 100644 --- a/src/MobileIDServiceProvider.php +++ b/src/MobileIDServiceProvider.php @@ -4,7 +4,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace kullar84\MobileID; +namespace kullar84\mobileid; use Illuminate\Support\ServiceProvider;