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

Set Authentication Token outside of Client creation #29

Open
namzug16 opened this issue Apr 25, 2024 · 1 comment
Open

Set Authentication Token outside of Client creation #29

namzug16 opened this issue Apr 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@namzug16
Copy link

Feature request

We should be able to set a different token from our service or anon one.

Is your feature request related to a problem? Please describe.

In cases where our RLS policies are more complex than normal(maybe checking individual user permissions) it is better to set the user token when needed instead of simply using the anon or service one

Describe the solution you'd like

A simple method to change the authorization header is enough

// Sets authorization header for subsequent requests
func (c *Client) SetAuthToken(authToken string) *Client {
  c.clientTransport.header.Set("Authorization", "Bearer "+authToken)
  return c
}

Question about apiKey and Authorization

I have not found any documentation on why apiKey is necessary on the storage api, in fact, while testing the api only asks you for an authorization header, that can be any token from the service, anon and user tokens

Is it necessary to have a SetApiKey method?

func (c *Client) SetApiKey(apiKey string) *Client {
  c.clientTransport.header.Set("apikey", apiKey)
  return c
}

I decided to take it out of my PR, but if it is necessary to have I'll added it back

More context

postgrest-go has implemented something similar

@namzug16 namzug16 added the enhancement New feature or request label Apr 25, 2024
@krish-adi
Copy link

hey @namzug16 , instead of reusing a client, would creating a new client for each request not be feasible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants