PHP code example of kullar84 / mobileid

1. Go to this page and download the library: Download kullar84/mobileid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kullar84 / mobileid example snippets


Route::group(['middleware' => 'session'], function () {
    Route::post('mlogin', 'AuthController@mlogin')->name('mlogin');
    Route::post('domlogin', 'AuthController@doMLogin')->name('domlogin');
});


use kullar84\mobileid\MobileIDAuthenticate;


protected function mlogin(Request $request)
{
	$this->validate(
		$request, [
			'phone' => 'se()->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);
}