Open ghstahl opened 1 year ago
Personal Access Token example
// PATTokenSource ...
type PATTokenSource struct {
PAT string
}
// Duration100Years ...
const Duration100Years = 100 * 365 * 24 * time.Hour
// Token ...
func (s *PATTokenSource) Token() (*oauth2.Token, error) {
return &oauth2.Token{
AccessToken: s.PAT,
TokenType: "Bearer",
Expiry: time.Now().Add(Duration100Years),
}, nil
}
// PATJWTProfileTokenSource ...
func PATJWTProfileTokenSource(pat string) middleware.JWTProfileTokenSource {
return func(issuer string, scopes []string) (oauth2.TokenSource, error) {
return &PATTokenSource{
PAT: pat,
}, nil
}
}
var options []zitadel.Option
options = append(options , zitadel.WithJWTProfileTokenSource(startup.PATJWTProfileTokenSource(ZitadelPersonalAccessToken)))
options = append(options, zitadel.WithInsecure())
Thanks for sharing this.
We will work on our go sdk in the coming sprint and I think this will be a super input.
CC @hifabienne since I am not sure who will work on this I am going to tag you :grin:
I just made a reference in the issue for the go sdk/examples
I would like to use the OAuth2 clientcredentials tokensource when using the SDK.
Its working, but it requires that I coerce JWTProfileTokenSource into doing something that it wasn't meant to do.
The library should only take a oauth2.TokenSource, where JWTProfileTokenSource return an oauth2.TokenSouce.
The same would work for a PAT version (i.e. static token).