Skip to content

Commit 07faf7c

Browse files
committed
make path configurable
1 parent 81e29c9 commit 07faf7c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/CareerBuilder/OAuth2/Flows/Flow.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ abstract class Flow
3232
protected $headers;
3333
/** @var array */
3434
protected $body;
35+
/** @var string */
36+
private $tokenRequestPath;
3537

3638
/**
3739
* @param array $configs
@@ -40,18 +42,34 @@ abstract class Flow
4042
*/
4143
protected function __construct(array $configs, ClientInterface $client = null, LoggerInterface $logger = null)
4244
{
45+
$configs = array_merge($this->getDefaultConfig(), $configs);
4346
$this->setCredentials($configs);
4447
$this->setDefaults();
4548

46-
47-
if (isset($configs['auth_in_header']) && $configs['auth_in_header']) {
49+
if ($configs['auth_in_header']) {
4850
$this->headers['Authorization'] = $this->getAuthHeader();
4951
}
5052

5153
$this->logger = $logger ?: new NullLogger();
5254
$this->client = $client ?: new Client();
5355
$this->client->setBaseUrl($configs['base_url']);
5456
$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+
);
5573
}
5674

5775
/**
@@ -100,7 +118,7 @@ public function getToken(AccessToken $token = null)
100118
$this->buildBody();
101119
}
102120

103-
$request = $this->client->post('/oauth/token', $this->headers, $this->body);
121+
$request = $this->client->post($this->tokenRequestPath, $this->headers, $this->body);
104122
$response = $request->send();
105123
$data = $response->json();
106124

@@ -118,4 +136,4 @@ protected function getJWT($claims)
118136
{
119137
return JWT::encode($claims, $this->sharedSecret, 'HS512');
120138
}
121-
}
139+
}

0 commit comments

Comments
 (0)