-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
13 changed files
with
715 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "anwar/bankid", | ||
"description": "BankID authentication and filesinging for laravel implementation from dimafi/\u001b[D6/bank-id", | ||
"license": "MIT", | ||
"homepage": "https://github.com/dimafe6/bank-id", | ||
"homepage": "https://github.com/ringkubd/bankid", | ||
"authors": [ | ||
{ | ||
"name": "MD ANWAR JAHID", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Dmitry Feshchenko", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Oleg Davudyuk", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Anders Fajerson", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Puggan", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Anwar\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php" : ">=5.6.0", | ||
"ext-soap":"*" | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Anwar\\Bankid\\BankidServiceProvider" | ||
] | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
|
||
namespace Anwar\Bankid; | ||
|
||
use Anwar\Bankid\Helper\CollectResponse; | ||
use Anwar\Bankid\Helper\OrderResponse; | ||
use App\Http\Controllers\Controller; | ||
use OutOfBoundsException; | ||
use ReflectionClass; | ||
use SoapClient; | ||
|
||
class BankidController extends Controller { | ||
/** | ||
* Bank ID Sign method name | ||
*/ | ||
const METHOD_SIGN = 'Sign'; | ||
/** | ||
* Bank ID Authenticate method name | ||
*/ | ||
const METHOD_AUTH = 'Authenticate'; | ||
/** | ||
* Bank ID Collect method name | ||
*/ | ||
const METHOD_COLLECT = 'Collect'; | ||
/** | ||
* @var SoapClient | ||
*/ | ||
private $client; | ||
/** | ||
* @var string | ||
*/ | ||
private $wsdlUrl; | ||
/** | ||
* @var string | ||
*/ | ||
private $soapOptions; | ||
/** | ||
* BankIDService constructor. | ||
* @param string $wsdlUrl Bank ID API url | ||
* @param array $options SoapClient options | ||
* @param bool $enableSsl Enable SSL | ||
*/ | ||
public function __construct($wsdlUrl, $options = [], $enableSsl = false) { | ||
if (!$enableSsl) { | ||
$context = stream_context_create([ | ||
'ssl' => [ | ||
'verify_peer' => false, | ||
'verify_peer_name' => false, | ||
'allow_self_signed' => true, | ||
], | ||
]); | ||
$options['stream_context'] = $context; | ||
} | ||
$this->wsdlUrl = $wsdlUrl; | ||
$this->soapOptions = $options; | ||
$this->client = new SoapClient($this->wsdlUrl, $this->soapOptions); | ||
} | ||
/** | ||
* @return array | ||
* @author Dmytro Feshchenko <[email protected]> | ||
*/ | ||
private function availableMethods() { | ||
$class = new ReflectionClass(__CLASS__); | ||
$constants = $class->getConstants(); | ||
$results = array_filter($constants, function ($constant) { | ||
return false !== strpos($constant, 'METHOD_'); | ||
}, ARRAY_FILTER_USE_KEY); | ||
return array_values($results); | ||
} | ||
/** | ||
* @param $method | ||
* @return bool | ||
* @author Dmytro Feshchenko <[email protected]> | ||
*/ | ||
private function isMethodAvailable($method) { | ||
return in_array($method, $this->availableMethods()); | ||
} | ||
/** | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
* @author Dmytro Feshchenko <[email protected]> | ||
*/ | ||
public function soapCall($method, $parameters) { | ||
return $this->client->__soapCall($method, $parameters); | ||
} | ||
/** | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
* @throws \SoapFault | ||
* @throws \OutOfBoundsException | ||
* @author Dmytro Feshchenko <[email protected]> | ||
*/ | ||
public function call($method, $parameters) { | ||
if (!$this->isMethodAvailable($method)) { | ||
throw new OutOfBoundsException("Invalid method '$method'"); | ||
} | ||
if (!is_array($parameters)) { | ||
throw new \InvalidArgumentException('parameters must be is an array'); | ||
} | ||
return $this->soapCall($method, $parameters); | ||
} | ||
/** | ||
* @param $personalNumber | ||
* @param $userVisibleData | ||
* @param null $userHiddenData | ||
* @return OrderResponse | ||
*/ | ||
public function getSignResponse($personalNumber, $userVisibleData, $userHiddenData = null) { | ||
$parameters = [ | ||
'personalNumber' => $personalNumber, | ||
'userVisibleData' => base64_encode($userVisibleData), | ||
]; | ||
if (!empty($userHiddenData)) { | ||
$parameters['userNonVisibleData'] = base64_encode($userHiddenData); | ||
} | ||
$options = ['parameters' => $parameters]; | ||
$response = $this->call(self::METHOD_SIGN, $options); | ||
$orderResponse = new OrderResponse(); | ||
$orderResponse->orderRef = $response->orderRef; | ||
$orderResponse->autoStartToken = $response->autoStartToken; | ||
return $orderResponse; | ||
} | ||
/** | ||
* @param $personalNumber | ||
* @return OrderResponse | ||
* @throws \SoapFault | ||
*/ | ||
public function getAuthResponse($personalNumber) { | ||
$parameters = [ | ||
'personalNumber' => $personalNumber, | ||
]; | ||
$options = ['parameters' => $parameters]; | ||
$response = $this->call(self::METHOD_AUTH, $options); | ||
$orderResponse = new OrderResponse(); | ||
$orderResponse->orderRef = $response->orderRef; | ||
$orderResponse->autoStartToken = $response->autoStartToken; | ||
return $orderResponse; | ||
} | ||
/** | ||
* @param string $orderRef | ||
* @return CollectResponse | ||
* @throws \SoapFault | ||
*/ | ||
public function collectResponse($orderRef) { | ||
$response = $this->call(self::METHOD_COLLECT, ['orderRef' => $orderRef]); | ||
$collect = new CollectResponse(); | ||
$collect->progressStatus = $response->progressStatus; | ||
if ($collect->progressStatus == CollectResponse::PROGRESS_STATUS_COMPLETE) { | ||
$collect->userInfo = $response->userInfo; | ||
$collect->signature = $response->signature; | ||
$collect->ocspResponse = $response->ocspResponse; | ||
} | ||
return $collect; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
|
||
namespace Anwar\Bankid; | ||
|
||
use Anwar\Bankid\Helper\CollectResponse; | ||
use Anwar\Bankid\Helper\OrderResponse; | ||
use App\Http\Controllers\Controller; | ||
use OutOfBoundsException; | ||
use ReflectionClass; | ||
use SoapClient; | ||
|
||
class BankidController extends Controller { | ||
/** | ||
* Bank ID Sign method name | ||
*/ | ||
const METHOD_SIGN = 'Sign'; | ||
/** | ||
* Bank ID Authenticate method name | ||
*/ | ||
const METHOD_AUTH = 'Authenticate'; | ||
/** | ||
* Bank ID Collect method name | ||
*/ | ||
const METHOD_COLLECT = 'Collect'; | ||
/** | ||
* @var SoapClient | ||
*/ | ||
private $client; | ||
/** | ||
* @var string | ||
*/ | ||
private $wsdlUrl; | ||
/** | ||
* @var string | ||
*/ | ||
private $soapOptions; | ||
/** | ||
* BankIDService constructor. | ||
* @param string $wsdlUrl Bank ID API url | ||
* @param array $options SoapClient options | ||
* @param bool $enableSsl Enable SSL | ||
*/ | ||
public function __construct($wsdlUrl, $options = [], $enableSsl = false) { | ||
if (!$enableSsl) { | ||
$context = stream_context_create([ | ||
'ssl' => [ | ||
'verify_peer' => false, | ||
'verify_peer_name' => false, | ||
'allow_self_signed' => true, | ||
], | ||
]); | ||
$options['stream_context'] = $context; | ||
} | ||
$this->wsdlUrl = $wsdlUrl; | ||
$this->soapOptions = $options; | ||
$this->client = new SoapClient($this->wsdlUrl, $this->soapOptions); | ||
} | ||
/** | ||
* @return array | ||
* @author Dmytro Feshchenko <[email protected]> | ||
*/ | ||
private function availableMethods() { | ||
$class = new ReflectionClass(__CLASS__); | ||
$constants = $class->getConstants(); | ||
$results = array_filter($constants, function ($constant) { | ||
return false !== strpos($constant, 'METHOD_'); | ||
}, ARRAY_FILTER_USE_KEY); | ||
return array_values($results); | ||
} | ||
/** | ||
* @param $method | ||
* @return bool | ||
* @author Dmytro Feshchenko <[email protected]> | ||
*/ | ||
private function isMethodAvailable($method) { | ||
return in_array($method, $this->availableMethods()); | ||
} | ||
/** | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
* @author Dmytro Feshchenko <[email protected]> | ||
*/ | ||
public function soapCall($method, $parameters) { | ||
return $this->client->__soapCall($method, $parameters); | ||
} | ||
/** | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
* @throws \SoapFault | ||
* @throws \OutOfBoundsException | ||
* @author Dmytro Feshchenko <[email protected]> | ||
*/ | ||
public function call($method, $parameters) { | ||
if (!$this->isMethodAvailable($method)) { | ||
throw new OutOfBoundsException("Invalid method '$method'"); | ||
} | ||
if (!is_array($parameters)) { | ||
throw new \InvalidArgumentException('parameters must be is an array'); | ||
} | ||
return $this->soapCall($method, $parameters); | ||
} | ||
/** | ||
* @param $personalNumber | ||
* @param $userVisibleData | ||
* @param null $userHiddenData | ||
* @return OrderResponse | ||
*/ | ||
public function getSignResponse($personalNumber, $userVisibleData, $userHiddenData = null) { | ||
$parameters = [ | ||
'personalNumber' => $personalNumber, | ||
'userVisibleData' => base64_encode($userVisibleData), | ||
]; | ||
if (!empty($userHiddenData)) { | ||
$parameters['userNonVisibleData'] = base64_encode($userHiddenData); | ||
} | ||
$options = ['parameters' => $parameters]; | ||
$response = $this->call(self::METHOD_SIGN, $options); | ||
$orderResponse = new OrderResponse(); | ||
$orderResponse->orderRef = $response->orderRef; | ||
$orderResponse->autoStartToken = $response->autoStartToken; | ||
return $orderResponse; | ||
} | ||
/** | ||
* @param $personalNumber | ||
* @return OrderResponse | ||
* @throws \SoapFault | ||
*/ | ||
public function getAuthResponse($personalNumber) { | ||
$parameters = [ | ||
'personalNumber' => $personalNumber, | ||
]; | ||
$options = ['parameters' => $parameters]; | ||
$response = $this->call(self::METHOD_AUTH, $options); | ||
$orderResponse = new OrderResponse(); | ||
$orderResponse->orderRef = $response->orderRef; | ||
$orderResponse->autoStartToken = $response->autoStartToken; | ||
return $orderResponse; | ||
} | ||
/** | ||
* @param string $orderRef | ||
* @return CollectResponse | ||
* @throws \SoapFault | ||
*/ | ||
public function collectResponse($orderRef) { | ||
$response = $this->call(self::METHOD_COLLECT, ['orderRef' => $orderRef]); | ||
$collect = new CollectResponse(); | ||
$collect->progressStatus = $response->progressStatus; | ||
if ($collect->progressStatus == CollectResponse::PROGRESS_STATUS_COMPLETE) { | ||
$collect->userInfo = $response->userInfo; | ||
$collect->signature = $response->signature; | ||
$collect->ocspResponse = $response->ocspResponse; | ||
} | ||
return $collect; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Anwar\Bankid; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class BankidServiceProvider extends ServiceProvider { | ||
/** | ||
* Bootstrap services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() { | ||
// | ||
} | ||
|
||
/** | ||
* Register services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() { | ||
$this->app->make('Anwar\Bankid\BankidController'); | ||
$this->app->bind('BankID', function () { | ||
return new BankidController; | ||
}); | ||
} | ||
} |
Oops, something went wrong.