@@ -32,6 +32,8 @@ abstract class Flow
32
32
protected $ headers ;
33
33
/** @var array */
34
34
protected $ body ;
35
+ /** @var string */
36
+ private $ tokenRequestPath ;
35
37
36
38
/**
37
39
* @param array $configs
@@ -40,18 +42,34 @@ abstract class Flow
40
42
*/
41
43
protected function __construct (array $ configs , ClientInterface $ client = null , LoggerInterface $ logger = null )
42
44
{
45
+ $ configs = array_merge ($ this ->getDefaultConfig (), $ configs );
43
46
$ this ->setCredentials ($ configs );
44
47
$ this ->setDefaults ();
45
48
46
-
47
- if (isset ($ configs ['auth_in_header ' ]) && $ configs ['auth_in_header ' ]) {
49
+ if ($ configs ['auth_in_header ' ]) {
48
50
$ this ->headers ['Authorization ' ] = $ this ->getAuthHeader ();
49
51
}
50
52
51
53
$ this ->logger = $ logger ?: new NullLogger ();
52
54
$ this ->client = $ client ?: new Client ();
53
55
$ this ->client ->setBaseUrl ($ configs ['base_url ' ]);
54
56
$ this ->client ->addSubscriber (new LogPlugin (new PsrLogAdapter ($ this ->logger )));
57
+ $ this ->tokenRequestPath = $ configs ['token_request_path ' ];
58
+ }
59
+
60
+ /**
61
+ * @return array
62
+ */
63
+ private function getDefaultConfig ()
64
+ {
65
+ return array (
66
+ 'client_id ' => '' ,
67
+ 'client_secret ' => '' ,
68
+ 'shared_secret ' => '' ,
69
+ 'base_url ' => 'https://api.careerbuilder.com ' ,
70
+ 'token_request_path ' => '/oauth/token ' ,
71
+ 'auth_in_header ' => false
72
+ );
55
73
}
56
74
57
75
/**
@@ -100,7 +118,7 @@ public function getToken(AccessToken $token = null)
100
118
$ this ->buildBody ();
101
119
}
102
120
103
- $ request = $ this ->client ->post (' /oauth/token ' , $ this ->headers , $ this ->body );
121
+ $ request = $ this ->client ->post ($ this -> tokenRequestPath , $ this ->headers , $ this ->body );
104
122
$ response = $ request ->send ();
105
123
$ data = $ response ->json ();
106
124
@@ -118,4 +136,4 @@ protected function getJWT($claims)
118
136
{
119
137
return JWT ::encode ($ claims , $ this ->sharedSecret , 'HS512 ' );
120
138
}
121
- }
139
+ }
0 commit comments