Skip to content

Make auth provider configurable #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,21 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
* Connects DBSQLClient to endpoint
* @public
* @param options - host, path, and token are required
* @param authProvider - Optional custom authentication provider
* @returns Session object that can be used to execute statements
* @example
* const session = client.connect({host, path, token});
*/
async connect(options: ConnectionOptions): Promise<IDBSQLClient> {
this.authProvider = new PlainHttpAuthentication({
username: 'token',
password: options.token,
headers: {
'User-Agent': buildUserAgentString(options.clientId),
},
});
async connect(options: ConnectionOptions, authProvider?: IAuthentication): Promise<IDBSQLClient> {
this.authProvider =
authProvider ||
new PlainHttpAuthentication({
username: 'token',
password: options.token,
headers: {
'User-Agent': buildUserAgentString(options.clientId),
},
});

this.connection = await this.connectionProvider.connect(this.getConnectionOptions(options), this.authProvider);

Expand Down