I’m authorizing my users using the Cognito Hosted UI from a custom guard. However the only way I can get the user redirected to the Hosted UI is by setting the headers myself, like so:
header("Location: https://{$this->domain}/login?scope=email+openid&$query");
exit;
However this is the wrong way to redirect within Laravel. If I attempt to use redirect()->away() then nothing happens, my protected page gets loaded regardless.
Here is my authenticate method, removed the rest of the code as it’s irrelevant:
// CognitoUserProvider.php
public function authenticate()
{
redirect()->away("https://{$this->domain}/login?scope=email+openid&$query");
}
// AuthServiceProvider.php
public function boot()
{
$this->registerPolicies();
Auth::extend('cognito', static function () {
return new CognitoUserProvider();
});
}