Skip to content

Commit feba37e

Browse files
Use Bearer token - instead of Basic authentication (#126)
Use Bearer token - instead of Basic authentication in the API authorization header. This supports use of AAD tokens and PAT tokens. Signed-off-by: divyavanmahajan <divyavanmahajan@users.noreply.github.com> Co-authored-by: Levko Kravets <levko.ne@gmail.com>
1 parent 832078d commit feba37e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

docs/readme.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22

33
## Table of Contents
44

5-
1. [Foreword](#foreword)
6-
2. [Example](#example) \
7-
2.1. [Error handling](#error-handling)
8-
3. [DBSQLSession](#dbsqlsession)
9-
4. [DBSQLOperation](#dbsqloperation)
10-
5. [Status](#status)
11-
6. [Finalize](#finalize)
5+
- [Getting started](#getting-started)
6+
- [Table of Contents](#table-of-contents)
7+
- [Foreword](#foreword)
8+
- [Example](#example)
9+
- [Error handling](#error-handling)
10+
- [DBSQLSession](#dbsqlsession)
11+
- [DBSQLOperation](#dbsqloperation)
12+
- [Example](#example-1)
13+
- [Status](#status)
14+
- [Finalize](#finalize)
1215

1316
## Foreword
1417

1518
The library is written using TypeScript, so the best way to get to know how it works is to look through the code [lib/](/lib/), [tests/e2e](/tests/e2e/) and [examples](/examples).
1619

1720
If you find any mistakes, misleading or some confusion feel free to create an issue or send a pull request.
1821

22+
The token can be a workspace PAT token or an Azure AD access token. To generate an AAD token, use the command line `az account get-access-token --resource 2ff814a6-3304-4ab8-85cb-cd0e6f879c1d` or use the MSAL authentication library with `scope = 2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default`.
23+
1924
## Example
2025

2126
```javascript

lib/connection/auth/PlainHttpAuthentication.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ export default class PlainHttpAuthentication implements IAuthentication {
2929
}
3030

3131
private getToken(username: string, password: string): string {
32-
return `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
32+
return `Bearer ${password}`;
3333
}
3434
}

tests/unit/connection/auth/PlainHttpAuthentication.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('PlainHttpAuthentication', () => {
3434
const transportMock = {
3535
setOptions(name, value) {
3636
expect(name).to.be.eq('headers');
37-
expect(value.Authorization).to.be.eq('Basic YW5vbnltb3VzOmFub255bW91cw==');
37+
expect(value.Authorization).to.be.eq('Bearer anonymous');
3838
},
3939
};
4040
return auth.authenticate(transportMock).then((transport) => {

0 commit comments

Comments
 (0)