Skip to content
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

Add bearer authentication #55

Conversation

danielgattiluxor
Copy link

@danielgattiluxor danielgattiluxor commented Aug 29, 2022

Add bearer authentication

@cla-bot
Copy link

cla-bot bot commented Aug 29, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@danielgattiluxor danielgattiluxor changed the title Add bearer authorization Add bearer authentication Aug 29, 2022
@danielgattiluxor danielgattiluxor force-pushed the add-bearer-authorization branch from 10a2b71 to 88b8b7f Compare August 29, 2022 13:42
@cla-bot
Copy link

cla-bot bot commented Aug 29, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@@ -130,6 +130,8 @@ const (
trinoAddedPrepareHeader = trinoHeaderPrefix + `Added-Prepare`
trinoDeallocatedPrepareHeader = trinoHeaderPrefix + `Deallocated-Prepare`

authorization = `Authorization`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this supposed to be Authentication?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this would be Authorization to match "Authorization: Bearer {token}"

@@ -71,6 +71,10 @@ This driver supports Kerberos authentication by setting up the Kerberos fields i

Please refer to the [Coordinator Kerberos Authentication](https://trino.io/docs/current/security/server.html) for server-side configuration.

#### Bearer authentication

This driver supports Bearer authentication (also called token authentication) by setting it in the [Config](https://godoc.org/github.com/trinodb/trino-go-client/trino#Config) struct.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs an example, especially if users are supposed to prefix any tokens with Bearer.

@@ -227,6 +230,7 @@ func (c *Config) FormatDSN() (string, error) {
"session_properties": strings.Join(sessionkv, ","),
"extra_credentials": strings.Join(credkv, ","),
"custom_client": c.CustomClientName,
"bearer_auth": c.BearerAuth,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a test, ideally an integration one, where you would configure the Trino server to accept this kind of authentication.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like this feature , if its not too much to ask, can I continue on this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, you can copy this branch into your fork and open up a second PR.

@@ -332,6 +336,7 @@ func newConn(dsn string) (*Conn, error) {
trinoSchemaHeader: query.Get("schema"),
trinoSessionHeader: query.Get("session_properties"),
trinoExtraCredentialHeader: query.Get("extra_credentials"),
authorization: query.Get("bearer_auth"),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to change the code a bit in the line#342 as

 if v != "" {
                    if k == "Authorization" {
                        c.httpHeaders.Add(k, fmt.Sprintf("Bearer %s", v))
                    }else {
                        c.httpHeaders.Add(k, v)
                    }

@nineinchnick
Copy link
Member

Superseded by #113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants