Skip to content
This repository was archived by the owner on Aug 28, 2021. It is now read-only.

Commit 9a6bbf8

Browse files
author
Ben Speakman
committed
Add auth
1 parent 2b11504 commit 9a6bbf8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Cyberduck/LaravelWpApi/LaravelWpApiServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ public function register()
3434
$this->app->bindShared('wp-api', function ($app) {
3535

3636
$endpoint = $this->app['config']->get('wp-api.endpoint');
37+
$auth = $this->app['config']->get('wp-api.auth');
3738
$client = new Client();
3839

39-
return new WpApi($endpoint, $client);
40+
return new WpApi($endpoint, $client, $auth);
4041

4142
});
4243

src/Cyberduck/LaravelWpApi/WpApi.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ class WpApi
77

88
protected $client;
99

10-
public function __construct($endpoint, Client $client)
10+
public function __construct($endpoint, Client $client, $auth = null)
1111
{
1212
$this->endpoint = $endpoint;
1313
$this->client = $client;
14+
$this->auth = $auth;
1415
}
1516

1617
public function posts($page = null)
@@ -73,7 +74,13 @@ public function _get($method, array $query = array())
7374

7475
try {
7576

76-
$response = $this->client->get($this->endpoint . '/wp-json/' . $method, ['query' => $query]);
77+
$query = ['query' => $query];
78+
79+
if($this->auth) {
80+
$query['auth'] = $this->auth;
81+
}
82+
83+
$response = $this->client->get($this->endpoint . '/wp-json/' . $method, $query);
7784

7885
$return = [
7986
'results' => $response->json(),

0 commit comments

Comments
 (0)