Skip to content

Commit a8418aa

Browse files
author
Artem Shteltser
committed
Added auth strategies to readme
1 parent c912b0c commit a8418aa

File tree

2 files changed

+71
-21
lines changed

2 files changed

+71
-21
lines changed

README.md

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,6 @@ via **yarn**:
2828
$ yarn add bitbucket
2929
```
3030

31-
## Authentication
32-
33-
Bitbucket supports different authentication strategies:
34-
35-
- OAuth 2
36-
- App passwords
37-
- Basic auth
38-
39-
### Basic auth
40-
41-
```javascript
42-
const { Bitbucket } = require('bitbucket')
43-
44-
const bitbucket = new Bitbucket({
45-
auth: '',
46-
})
47-
```
48-
4931
## Usage
5032

5133
### Browser
@@ -80,7 +62,13 @@ const clientOptions = {
8062
const bitbucket = new Bitbucket(clientOptions)
8163
```
8264

83-
#### Authentication
65+
### Authentication
66+
67+
Bitbucket supports different authentication strategies:
68+
69+
- OAuth 2
70+
- App passwords
71+
- Basic auth
8472

8573
**Using `username` and `password`**:
8674

@@ -107,6 +95,68 @@ const clientOptions = {
10795
const bitbucket = new Bitbucket(clientOptions)
10896
```
10997

98+
**Using `Client Credentials Grant`**:
99+
100+
```js
101+
const clientOptions = {
102+
authStrategy: 'OAuth',
103+
auth: {
104+
grant_type: 'clientCredentialsGrant',
105+
client_id: 'client_id',
106+
client_secret: 'client_secret',
107+
},
108+
}
109+
110+
const bitbucket = new Bitbucket(clientOptions)
111+
```
112+
113+
**Using `Authorization Code Grant`**:
114+
115+
```js
116+
const clientOptions = {
117+
authStrategy: 'OAuth',
118+
auth: {
119+
grant_type: 'authorizationCodeGrant',
120+
client_id: 'client_id',
121+
client_secret: 'client_secret',
122+
code: 'code',
123+
},
124+
}
125+
126+
const bitbucket = new Bitbucket(clientOptions)
127+
```
128+
129+
**Using `Resource Owner Password Credentials Grant`**:
130+
131+
```js
132+
const clientOptions = {
133+
authStrategy: 'OAuth',
134+
auth: {
135+
grant_type: 'resourceOwnerPasswordCredentialsGrant',
136+
client_id: 'client_id',
137+
client_secret: 'client_secret',
138+
username: 'username',
139+
password: 'password',
140+
},
141+
}
142+
143+
const bitbucket = new Bitbucket(clientOptions)
144+
```
145+
146+
**Using `Bitbucket Cloud JWT Grant`**:
147+
148+
```js
149+
const clientOptions = {
150+
authStrategy: 'OAuth',
151+
auth: {
152+
grant_type: 'urn:bitbucket:oauth2:jwt',
153+
jwt_token: 'jwt_token',
154+
},
155+
}
156+
157+
const bitbucket = new Bitbucket(clientOptions)
158+
```
159+
110160
#### API Methods
111161

112162
**async/await**

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Client } from './client'
2-
import authenticatePlugin from './plugins/auth'
2+
import authPlugin from './plugins/auth'
33
import noticePlugin from './plugins/notice'
44
import paginationPlugin from './plugins/pagination'
55
import registerApiEndpointsPlugin from './plugins/register-api-endpoints'
@@ -12,7 +12,7 @@ const Plugins = [
1212
registerEndpointsPlugin,
1313
registerApiEndpointsPlugin,
1414
validateRequestPlugin,
15-
authenticatePlugin,
15+
authPlugin,
1616
]
1717

1818
export const Bitbucket = Client.plugins(Plugins)

0 commit comments

Comments
 (0)