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

feat: add static token option in client #187

Closed

Conversation

TakumiHaruta
Copy link

Description

Close #186

  • Renamed NewAuthenticator to NewJWTProfileAuthenticator since this function is JWT profile specific.
  • Added StaticTokenSource type for credentials.PerRPCCredentials interface
  • Set credentials in NewConnection and switch authentication method by c.staticTokenSource is empty or not

Note

The function NewConnection itself is a bit tightly-coupled to JWT profile method only, so I think the condition to switch auth methods inside NewConnection is not quite clean. Please let me know if you have an idea how to handle this in a better way

Copy link
Member

@livio-a livio-a left a comment

Choose a reason for hiding this comment

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

hey @TakumiHaruta

I was finally able to have a look at your PR. Thanks for your patience and the PR itself 😃

Please have a look at the comments. And i have an additional question:
In your issue you describe that you intend to use pass access token from the header of your frontend. How do you handle this if you use a static token? Don't you need to create a new client for every request?

//There returned token will be used for authorization in all calls
//if expired, the token will be automatically refreshed
func NewAuthenticator(issuer string, jwtProfileTokenSource JWTProfileTokenSource, scopes ...string) (*AuthInterceptor, error) {
func NewJWTProfileAuthenticator(issuer string, jwtProfileTokenSource JWTProfileTokenSource, scopes ...string) (*AuthInterceptor, error) {
Copy link
Member

Choose a reason for hiding this comment

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

although it's probably not used directly in other projects, renaming it would be a breaking change... but it could be solved with a wrapper method:

...
// Deprecated: use NewJWTProfileAuthenticator instead
func NewAuthenticator(issuer string, jwtProfileTokenSource JWTProfileTokenSource, scopes ...string) (*AuthInterceptor, error) {
  return NewJWTProfileAuthenticator(issuer, jwtProfileTokenSource, scopes...)
}

func NewJWTProfileAuthenticator(issuer string, jwtProfileTokenSource JWTProfileTokenSource, scopes ...string) (*AuthInterceptor, error) {
...

Comment on lines +104 to +106
func (a StaticTokenSource) RequireTransportSecurity() bool {
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

IMO it should be possible to configure if TLS is used or not and i would prefer to have it enabled by default and that you would need to disable it explicitly

Comment on lines +44 to +63
if c.staticTokenSource == "" {
err := c.setInterceptors(c.issuer, c.orgID, c.scopes, c.jwtProfileTokenSource)
if err != nil {
return nil, err
}
dialOptions = append(dialOptions,
grpc.WithChainUnaryInterceptor(
c.unaryInterceptors...,
),
grpc.WithChainStreamInterceptor(
c.streamInterceptors...,
),
)
} else {
c.setCredentials(c.staticTokenSource)
dialOptions = append(dialOptions,
grpc.WithPerRPCCredentials(
c.perRPCCredentials,
),
)
Copy link
Member

Choose a reason for hiding this comment

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

the setInterceptors method also sets an interceptor for the x-zitadel-orgid header (allows to specify another organisation if needed)
IMO the static token version might need that as well

@livio-a
Copy link
Member

livio-a commented May 24, 2023

Hey @TakumiHaruta

Just wanted to check the state on this PR. Maybe you missed my review.
We would appreciate your contribution 😃

@TakumiHaruta
Copy link
Author

@livio-a
Hi, sorry for the late reply. Currently I don't have time to spend on contributions...
Is it possible for you to fork from my PR and modify it as you want?
As long as we can put an access token from Authorization header in go client to use Zitadel API, it's totally fine for us.

@livio-a
Copy link
Member

livio-a commented May 24, 2023

@livio-a Hi, sorry for the late reply. Currently I don't have time to spend on contributions... Is it possible for you to fork from my PR and modify it as you want? As long as we can put an access token from Authorization header in go client to use Zitadel API, it's totally fine for us.

no worries, just wanted to check. i will be on vacation but might check afterwards if i find a solution

@hifabienne hifabienne added the os-contribution This is a contribution from our open-source community label Oct 27, 2023
@muhlemmer muhlemmer added the waiting waiting on changes or reply after review or comments label Nov 9, 2023
@hifabienne
Copy link
Member

This PR is more than a year old, and the go lib has been refactored since then.
Due to this I will close this PR

@hifabienne hifabienne closed this Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os-contribution This is a contribution from our open-source community waiting waiting on changes or reply after review or comments
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add option to use static token for Connection
5 participants