Skip to content

feat(http): Add support for fetch credentials options in HttpClient #62354

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

Closed

Conversation

SkyZeroZx
Copy link
Contributor

@SkyZeroZx SkyZeroZx commented Jun 28, 2025

The change includes:

  • Added credentials to the HttpRequestInit interface
  • Modified FetchBackend to pass the credentials option to the native fetch call
  • Added unit tests to validate correct handling of the credentials option

Motivation / Use Cases

The credentials option is particularly useful for:

  • Controlling whether cookies and HTTP authentication information are sent with requests ('omit', 'same-origin', 'include')
  • Enabling proper CORS requests with credentials when needed
  • Improving security and compliance with server authentication policies

Proposed Solution

  • Add credentials to the HttpRequestInit interface
  • Implement property handling in the HttpRequest class
  • Pass the credentials option through FetchBackend to the native Fetch API
  • Maintain backward compatibility by defaulting to existing behavior if not specified

Examples of New Usage

// GET request with credentials included
http.get('/api/user-data', {
  credentials: 'include'
}).subscribe();

Implementation Details / Compatibility Handling

  • The credentials option is primarily read from the new req.credentials property.
  • For backward compatibility, if req.withCredentials is true (legacy Angular option), credentials is set to 'include' ( override ).
  • This ensures existing code using withCredentials continues to work as expected while enabling the new Fetch API credentials option.

Extend Angular's HttpClient to accept the 'credentials' option from the Fetch API.
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: common/http Issues related to HTTP and HTTP Client labels Jun 28, 2025
@ngbot ngbot bot added this to the Backlog milestone Jun 28, 2025
Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

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

LGTM!

reviewed-for: fw-general, public-api

@pullapprove pullapprove bot requested review from crisbeto and kirjs June 30, 2025 08:52
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Jun 30, 2025
@thePunderWoman
Copy link
Contributor

This PR was merged into the repository by commit f0965c7.

The changes were merged into the following branches: main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: common/http Issues related to HTTP and HTTP Client detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants