( //nolint:ireturn ctx context.Context, client *http.Client, dbg bool, unauth UnauthorizedHandler, isUnauth IsUnauthorizedDecider, info *ProviderInfo, cfg *OAuth2AuthCodeParams, )
| 504 | authClient, err = common.NewBasicAuthHTTPClient(ctx, user, pass, opts...) |
| 505 | if err != nil { |
| 506 | return nil, fmt.Errorf("%w: failed to create basic auth client: %w", ErrClient, err) |
| 507 | } |
| 508 | |
| 509 | return authClient, nil |
| 510 | } |
| 511 | |
| 512 | func createOAuth2AuthCodeHTTPClient( //nolint:ireturn |
| 513 | ctx context.Context, |
| 514 | client *http.Client, |
| 515 | dbg bool, |
| 516 | unauth UnauthorizedHandler, |
| 517 | isUnauth IsUnauthorizedDecider, |
| 518 | info *ProviderInfo, |
| 519 | cfg *OAuth2AuthCodeParams, |
| 520 | ) (common.AuthenticatedHTTPClient, error) { |
| 521 | if cfg == nil { |
| 522 | return nil, fmt.Errorf("%w: oauth2 config not provided", ErrClient) |
| 523 | } |
| 524 | |
| 525 | options := []common.OAuthOption{ |
| 526 | common.WithOAuthClient(getClient(client)), |
| 527 | common.WithOAuthConfig(cfg.Config), |
| 528 | common.WithOAuthToken(cfg.Token), |
| 529 | } |
| 530 | |
| 531 | if dbg { |
| 532 | options = append(options, common.WithOAuthDebug(common.PrintRequestAndResponse)) |
| 533 | } |
| 534 | |
| 535 | var oauthClient common.AuthenticatedHTTPClient |
| 536 | |
| 537 | if isUnauth != nil { |
| 538 | options = append(options, common.WithOAuthIsUnauthorizedHandler(isUnauth)) |
| 539 | } |
| 540 | |
| 541 | if unauth != nil { |
| 542 | options = append(options, |
| 543 | common.WithOAuthUnauthorizedHandler( |
| 544 | func(token *oauth2.Token, req *http.Request, rsp *http.Response) (*http.Response, error) { |
| 545 | return unauth(oauthClient, &UnauthorizedEvent{ |
| 546 | Provider: info, |
| 547 | OAuthToken: token, |
| 548 | Request: req, |
| 549 | Response: rsp, |
| 550 | }) |
| 551 | })) |
| 552 | } |
| 553 | |
| 554 | if header := CreateOauth2TokenHeaderAttachment(info); header != nil { |
| 555 | options = append(options, common.WithTokenHeaderAttachment(header)) |
| 556 | } |
| 557 | |
| 558 | options = append(options, cfg.Options...) |
| 559 | |
| 560 | var err error |
| 561 | |
| 562 | oauthClient, err = common.NewOAuthHTTPClient(ctx, options...) |
| 563 | if err != nil { |
no test coverage detected