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