-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add jwt auth (#524) #855
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,12 @@ export class BasicAuth implements Auth { | |
constructor(readonly username: string, readonly password?: string) {} | ||
} | ||
|
||
export class JwtAuth implements Auth { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a correct implementation. It should be closer to the implementation like the one in the python client: https://github.com/trinodb/trino-python-client/blob/df08367b54d7d27c1cd826ca3fa34ca0173f4c63/trino/auth.py#L295 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
readonly type: AuthType = 'bearer'; | ||
constructor(readonly jwt: string) {} | ||
} | ||
|
||
|
||
export type Session = {[key: string]: string}; | ||
|
||
export type ExtraCredential = {[key: string]: string}; | ||
|
@@ -170,9 +176,9 @@ const cleanHeaders = (headers: RawAxiosRequestHeaders) => { | |
}; | ||
|
||
/* It's a wrapper around the Axios library that adds some Trino specific headers to the requests */ | ||
class Client { | ||
export class Client { | ||
private constructor( | ||
private readonly clientConfig: AxiosRequestConfig, | ||
readonly clientConfig: AxiosRequestConfig, | ||
private readonly options: ConnectionOptions | ||
) {} | ||
|
||
|
@@ -205,6 +211,10 @@ class Client { | |
|
||
headers[TRINO_USER_HEADER] = basic.username; | ||
} | ||
else if (options.auth && options.auth.type === 'bearer') { | ||
const jwt: JwtAuth = <JwtAuth>options.auth; | ||
headers.Authorization = `Bearer ${jwt.jwt}`; | ||
} | ||
|
||
clientConfig.headers = cleanHeaders(headers); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.