MCPcopy Create free account
hub / github.com/auth0/auth0-cli / Token

Method Token

internal/auth/auth.go:290–329  ·  view source on GitHub ↗

Token generates a new token using Private Key JWT client authentication.

()

Source from the content-addressed store, hash-verified

288
289// Token generates a new token using Private Key JWT client authentication.
290func (p PrivateKeyJwtTokenSource) Token() (*oauth2.Token, error) {
291 alg, err := DetermineSigningAlgorithm(p.ClientAssertionSigningAlg)
292 if err != nil {
293 return nil, fmt.Errorf("invalid algorithm: %w", err)
294 }
295
296 baseURL, err := url.Parse(p.URI)
297 if err != nil {
298 return nil, fmt.Errorf("invalid URI: %w", err)
299 }
300
301 assertion, err := CreateClientAssertion(
302 alg,
303 p.ClientAssertionPrivateKey,
304 p.ClientID,
305 baseURL.JoinPath("/").String(),
306 )
307
308 if err != nil {
309 return nil, fmt.Errorf("failed to create client assertion: %w", err)
310 }
311
312 cfg := &clientcredentials.Config{
313 TokenURL: p.URI + "/oauth/token",
314 AuthStyle: oauth2.AuthStyleInParams,
315 EndpointParams: url.Values{
316 "audience": []string{p.Audience},
317 "client_assertion_type": []string{"urn:ietf:params:oauth:client-assertion-type:jwt-bearer"},
318 "client_assertion": []string{assertion},
319 "grant_type": []string{"client_credentials"},
320 },
321 }
322
323 token, err := cfg.Token(p.Ctx)
324 if err != nil {
325 return nil, fmt.Errorf("token request failed: %w", err)
326 }
327
328 return token, nil
329}
330
331// DetermineSigningAlgorithm returns the appropriate JWA signature algorithm based on the string representation.
332func DetermineSigningAlgorithm(alg string) (jwa.SignatureAlgorithm, error) {

Calls 3

CreateClientAssertionFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected