Skip to content

Commit 07217b6

Browse files
committed
+ Adding missing Authentication and SSL folders
1 parent 5ead441 commit 07217b6

File tree

12 files changed

+4798
-0
lines changed

12 files changed

+4798
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* ApiException
4+
5+
*/
6+
namespace CyberSource\Authentication\Core;
7+
8+
use \Exception;
9+
10+
/**
11+
* ApiException Class Doc Comment
12+
*
13+
* @category Class
14+
* @package CyberSource
15+
*/
16+
class AuthException extends Exception
17+
{
18+
19+
// Redefine the exception so message isn't optional
20+
public function __construct($message, $code = 0, Exception $previous = null) {
21+
22+
// make sure everything is assigned properly
23+
parent::__construct($message, $code, $previous);
24+
}
25+
26+
27+
}
28+
29+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/*
3+
Purpose : This is focusly on split the services HTTP or JWT
4+
*/
5+
namespace CyberSource\Authentication\Core;
6+
use CyberSource\Authentication\Http\HttpSignatureGenerator as HttpSignatureGenerator;
7+
use CyberSource\Authentication\Jwt\JsonWebTokenGenerator as JsonWebTokenGenerator;
8+
use CyberSource\Authentication\Util\GlobalParameter as GlobalParameter;
9+
use CyberSource\Authentication\Log\Logger as Logger;
10+
11+
class Authentication
12+
{
13+
private static $logger=null;
14+
/**
15+
* Constructor
16+
*/
17+
public function __construct()
18+
{
19+
if(self::$logger === null){
20+
self::$logger = new Logger(Authentication::class);
21+
}
22+
}
23+
24+
//call http signature and jwt
25+
function generateToken($resourcePath, $inputData, $method, $merchantConfig)
26+
{
27+
if(is_null($merchantConfig))
28+
{
29+
$exception = new AuthException(GlobalParameter::MERCHANTCONFIGERR, 0);
30+
self::$logger->log($merchantConfig, $exception);
31+
throw $exception;
32+
}
33+
34+
$tokenGenerator = $this->getTokenGenerator($merchantConfig);
35+
return $tokenGenerator->generateToken($resourcePath, $inputData, $method, $merchantConfig);
36+
}
37+
38+
function getTokenGenerator($merchantConfig) {
39+
$authType = $merchantConfig->getAuthenticationType();
40+
if($authType == GlobalParameter::HTTP_SIGNATURE) {
41+
return new HttpSignatureGenerator();
42+
} else if($authType == GlobalParameter::JWT){
43+
return new JsonWebTokenGenerator();
44+
} else {
45+
$exception = new AuthException(GlobalParameter::AUTH_ERROR, 0);
46+
self::$logger->log($merchantConfig, $exception);
47+
throw $exception;
48+
}
49+
}
50+
51+
}
52+
53+
54+
?>

0 commit comments

Comments
 (0)