public function BasicAuth::challengeException in Drupal 10
Same name and namespace in other branches
- 8 core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php \Drupal\basic_auth\Authentication\Provider\BasicAuth::challengeException()
- 9 core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php \Drupal\basic_auth\Authentication\Provider\BasicAuth::challengeException()
File
- core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php, line 130
Class
- BasicAuth
- HTTP Basic authentication provider.
Namespace
Drupal\basic_auth\Authentication\Provider
Code
public function challengeException(Request $request, \Exception $previous) {
$site_config = $this->configFactory
->get('system.site');
$site_name = $site_config
->get('name');
$challenge = new FormattableMarkup('Basic realm="@realm"', [
'@realm' => !empty($site_name) ? $site_name : 'Access restricted',
]);
$cacheability = CacheableMetadata::createFromObject($site_config)
->addCacheTags([
'config:user.role.anonymous',
])
->addCacheContexts([
'user.roles:anonymous',
]);
return $request
->isMethodCacheable() ? new CacheableUnauthorizedHttpException($cacheability, (string) $challenge, 'No authentication credentials provided.', $previous) : new UnauthorizedHttpException((string) $challenge, 'No authentication credentials provided.', $previous);
}