(ctx context.Context)
| 443 | } |
| 444 | |
| 445 | func (c *Connection) refreshAuthToken(ctx context.Context) (string, error) { |
| 446 | method, err := c.AuthMethod(ctx) |
| 447 | if err != nil { |
| 448 | return "", err |
| 449 | } |
| 450 | if method.Auth0 == nil { |
| 451 | return "", fmt.Errorf("auth not available on database: %s", c.hostURL) |
| 452 | } |
| 453 | tokens, err := c.auth.Tokens(c.hostURL) |
| 454 | if err != nil { |
| 455 | return "", err |
| 456 | } |
| 457 | if tokens == nil { |
| 458 | return "", fmt.Errorf("auth credentials not set for database: %s", c.hostURL) |
| 459 | } |
| 460 | client, err := auth0.NewClient(*method.Auth0) |
| 461 | if err != nil { |
| 462 | return "", err |
| 463 | } |
| 464 | refreshed, err := client.RefreshToken(ctx, tokens.Refresh) |
| 465 | if err != nil { |
| 466 | return "", err |
| 467 | } |
| 468 | if err := c.auth.SetTokens(c.hostURL, refreshed); err != nil { |
| 469 | return "", err |
| 470 | } |
| 471 | c.SetAuthToken(refreshed.Access) |
| 472 | return refreshed.Access, nil |
| 473 | } |
| 474 | |
| 475 | type ErrorResponse struct { |
| 476 | *http.Response |
no test coverage detected