Skip to content

Commit 54a8e2f

Browse files
committed
updated docs/authentication.md to reflect new changes.
1 parent 8caa961 commit 54a8e2f

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

docs/authentication.md

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,40 @@ Although you can access any public data without authentication, you need to auth
55
Bitbucket provides Basic and OAuth authentication.
66

77
### Basic authentication
8-
To use basic authentication, you need to instantiate `Basic` class from `Bitbucket\API\Authentication` namespace and pass it to `setCredentials()` method, before making first request.
9-
10-
```php
11-
$auth = new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass);
8+
To use basic authentication, you need to attach `BasicAuthListener` to http client with your username and password.
129

10+
```php
1311
$user = new Bitbucket\API\User();
14-
$user->setCredentials($auth);
15-
16-
// some code
12+
$user->getClient()->addListener(
13+
new Bitbucket\API\Http\Listener\BasicAuthListener($bb_user, $bb_pass)
14+
);
1715

18-
$invitation = new Bitbucket\API\Invitations();
19-
$invitation->setCredentials($auth);
20-
```
21-
22-
If you need to change credentials, two methods are available for this:
23-
```php
24-
$auth->setUsername('username');
25-
$auth->setPassword('password');
16+
// now you can access protected endpoints as $bb_user
17+
$response = $user->get();
2618
```
2719

2820
----
2921

3022
### OAuth authorization
31-
To use OAuth, you will need to instantiate `OAuth` class from `Bitbucket\API\Authentication` namespace and pass it to `setCredentials()` method, before making first request.
32-
`OAuth` accepts a string or array as constructor. Those parameters are actually OAuth parameters, that have been previously signed.
33-
34-
**NOTE:** `OAuth` class will _NOT_ sign the request. It will just build the authorization header from previously signed OAuth parameters.
23+
This library comes with a `OAuthListener` which will sign all requests for you. All you need to do is to attach the listener to http client with oauth credentials before making a request.
3524

3625
```php
37-
// use 3rd party OAuth library to sign the request and pass already signed parameters to `OAuth` class.
38-
39-
$auth = new Bitbucket\API\Authentication\OAuth(array(
40-
'oauth_version' => '1.0',
41-
'oauth_nonce' => 'aaaaaaaaaaaaaaa',
42-
'oauth_timestamp' => '1370771799',
43-
'oauth_consumer_key' => 'xxxxxxxxxxxxxxx',
44-
'oauth_signature_method' => 'HMAC-SHA1',
45-
'oauth_signature' => 'yyyyyyyyyyyyyyy'
46-
));
47-
48-
$user = new Bitbucket\API\User();
49-
$user->setCredentials($auth);
50-
```
51-
52-
You can also send the parameters as string, instead of array:
53-
```php
54-
// use 3rd party OAuth library to sign the request and pass already signed parameters to `OAuth` class.
55-
56-
$auth = new Bitbucket\API\Authentication\OAuth('oauth_version="1.0",oauth_nonce="aaaaaaaaaaaaaaa",oauth_timestamp="1370771799",oauth_consumer_key="xxxxxxxxxxxxxxx",oauth_signature_method="HMAC-SHA1",oauth_signature="yyyyyyyyyyyyyyy"');
57-
58-
// rest of the code
26+
// OAuth 1-legged example
27+
// You can create a new consumer at: https://bitbucket.org/account/user/<username or team>/api
28+
$oauth_params = array(
29+
'oauth_consumer_key' => 'aaa',
30+
'oauth_consumer_secret' => 'bbb'
31+
);
32+
33+
$user = new Bitbucket\API\User;
34+
$user->getClient()->addListener(
35+
new Bitbucket\API\Http\Listener\OAuthListener($oauth_params)
36+
);
37+
38+
// now you can access protected endpoints as consumer owner
39+
$response = $user->get();
5940
```
6041

61-
**NOTES:**
62-
63-
* `OAuth` class will prepend `Authorization: OAuth` to those parameters and will add the result to current request header.
64-
* When choosing an OAuth library, take into consideration the fact that [Bitbucket](https://bitbucket.org) uses OAuth 1.0a ( _3-Legged and 2-Legged_ )
65-
6642
----
6743

6844
#### Related:

0 commit comments

Comments
 (0)