@@ -42,6 +42,8 @@ abstract class Flow
42
42
protected $ headers ;
43
43
/** @var array */
44
44
protected $ body ;
45
+ /** @var string */
46
+ private $ tokenRequestPath ;
45
47
46
48
/**
47
49
* @param array $configs
@@ -50,18 +52,34 @@ abstract class Flow
50
52
*/
51
53
protected function __construct (array $ configs , ClientInterface $ client = null , LoggerInterface $ logger = null )
52
54
{
55
+ $ configs = array_merge ($ this ->getDefaultConfig (), $ configs );
53
56
$ this ->setCredentials ($ configs );
54
57
$ this ->setDefaults ();
55
58
56
-
57
- if (isset ($ configs ['auth_in_header ' ]) && $ configs ['auth_in_header ' ]) {
59
+ if ($ configs ['auth_in_header ' ]) {
58
60
$ this ->headers ['Authorization ' ] = $ this ->getAuthHeader ();
59
61
}
60
62
61
63
$ this ->logger = $ logger ?: new NullLogger ();
62
64
$ this ->client = $ client ?: new Client ();
63
65
$ this ->client ->setBaseUrl ($ configs ['base_url ' ]);
64
66
$ this ->client ->addSubscriber (new LogPlugin (new PsrLogAdapter ($ this ->logger )));
67
+ $ this ->tokenRequestPath = $ configs ['token_request_path ' ];
68
+ }
69
+
70
+ /**
71
+ * @return array
72
+ */
73
+ private function getDefaultConfig ()
74
+ {
75
+ return array (
76
+ 'client_id ' => '' ,
77
+ 'client_secret ' => '' ,
78
+ 'shared_secret ' => '' ,
79
+ 'base_url ' => 'https://api.careerbuilder.com ' ,
80
+ 'token_request_path ' => '/oauth/token ' ,
81
+ 'auth_in_header ' => false
82
+ );
65
83
}
66
84
67
85
/**
@@ -110,7 +128,7 @@ public function getToken(AccessToken $token = null)
110
128
$ this ->buildBody ();
111
129
}
112
130
113
- $ request = $ this ->client ->post (' /oauth/token ' , $ this ->headers , $ this ->body );
131
+ $ request = $ this ->client ->post ($ this -> tokenRequestPath , $ this ->headers , $ this ->body );
114
132
$ response = $ request ->send ();
115
133
$ data = $ response ->json ();
116
134
@@ -128,4 +146,4 @@ protected function getJWT($claims)
128
146
{
129
147
return JWT ::encode ($ claims , $ this ->sharedSecret , 'HS512 ' );
130
148
}
131
- }
149
+ }
0 commit comments