-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Add NTLM authentication support to Http Client #56475
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shaedrich
reviewed
Jul 29, 2025
Comment on lines
474
to
486
/** | ||
* Specify the digest authentication username and password for the request. | ||
* | ||
* @param string $username | ||
* @param string $password | ||
* @return $this | ||
*/ | ||
public function withNtlmAuth($username, $password) | ||
{ | ||
return tap($this, function () use ($username, $password) { | ||
$this->options['auth'] = [$username, $password, 'ntlm']; | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
/** | |
* Specify the digest authentication username and password for the request. | |
* | |
* @param string $username | |
* @param string $password | |
* @return $this | |
*/ | |
public function withNtlmAuth($username, $password) | |
{ | |
return tap($this, function () use ($username, $password) { | |
$this->options['auth'] = [$username, $password, 'ntlm']; | |
}); | |
} | |
/** | |
* Specify the authentication username and password for the request. | |
* | |
* @param string $username | |
* @param string $password | |
* @param string|null $type | |
* @return $this | |
*/ | |
public function withAuth($username, $password, $type) | |
{ | |
return tap($this, function () use ($username, $password) { | |
$this->options['auth'] = $type !== null | |
? [$username, $password, $type] | |
: [$username, $password]; | |
}); | |
} | |
/** | |
* Specify the digest authentication username and password for the request. | |
* | |
* @param string $username | |
* @param string $password | |
* @return $this | |
*/ | |
public function withNtlmAuth($username, $password) | |
{ | |
return $this->withAuth($username, $password, 'ntlm'); | |
}); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could even go a step further and validate the type:
/**
* @var string[]
*/
const SUPPORTED_AUTH_TYPES = ['ntlm', 'digest'];
/**
* Specify the authentication username and password for the request.
*
* @param string $username
* @param string $password
* @param value-of<SUPPORTED_AUTH_TYPES>|null $type `null` means 'basic'
* @return $this
*/
public function withAuth($username, $password, $type)
{
if ($type !== null && !in_array($type, self::SUPPORTED_AUTH_TYPES) {
throw new Exception(sprintf(
'Auth type "%s" not supported. Use one of: %s',
$type,
implode(', ', self::SUPPORTED_AUTH_TYPES),
));
}
return tap($this, function () use ($username, $password) {
$this->options['auth'] = $type !== null
? [$username, $password, $type]
: [$username, $password];
});
}
Co-authored-by: Sebastian Hädrich <[email protected]>
Note that this is broken if ext-curl is not installed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces NTLM authentication support for the Laravel HTTP Client, extending its capabilities for integrations with services that require this authentication method (e.g., certain Microsoft services or legacy APIs).
The implementation leverages Guzzle’s built‑in NTLM option: https://docs.guzzlephp.org/en/stable/request-options.html?highlight=ntlm
Example usage: