Skip to content

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

Closed
SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:add-credentials-fetch-http-client
Closed

SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:add-credentials-fetch-http-client

Conversation

@SkyZeroZx

@SkyZeroZx SkyZeroZx commented Jun 28, 2025 •

Copy link
Copy Markdown
Contributor

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

@thePunderWoman thePunderWoman left a comment

Copy link
Copy Markdown
Contributor

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

@crisbeto crisbeto left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

This PR was merged into the repository by commit f0965c7.

The changes were merged into the following branches: main

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 31, 2025
@SkyZeroZx
SkyZeroZx deleted the add-credentials-fetch-http-client branch December 17, 2025 21:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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