The Response content must be a string or object implementing __toString(), "object" given.
Jaspur opened this issue · 4 comments
When calling the URL correctly:
/autologin/dG2SlV5DIoGCarhxqLaLWOWHBcE1rScLsGi25SXFIGRi9UmXRp
It returns this:
method.
*
* @param mixed $content Content that can be cast to string
*
* @return $this
*
* @throws \UnexpectedValueException
*/
public function setContent($content)
{
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) {
throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
}
$this->content = (string) $content;
return $this;
}
/**
* Gets the current response content.
*
* @return string Content
*/
public function getContent()
{
return $this->content;
}
/**
* Sets the HTTP protocol version (1.0 or 1.1).
*
Just did all the things from the docs.
What file is that code from? That's not part of this library.
Can you provide more of your code to show how you've got it up in your app?
Your code:
Route::get('autologin/{tokenforautologin}', ['as' => 'autologin', 'uses' => '\Watson\Autologin\AutologinController@autologin']);
Implemented:
Route::get('foobar', 'FooController@bar')->middleware('auth:api');
public function bar()
{
$user = Auth::guard('api')->user();
$link = Autologin::user($user, '/support');
return redirect()->away((string) $link);
}
I'll have to take a look at this tomorrow - but am I understanding correctly that you have a user authenticated by your API and you want to redirect them to a link that will log them in with a standard session?
Also - I think you mean to use Autologin::to()
instead of Autologin::user()
as you're giving it a second argument for the path to go to.
I created an absolute barebones Laravel app with Autologin and it's working fine. I'm not convinced that the error you are seeing is related to this package at all. If you can provide a complete stack trace of the error then I'll be able to dig in further and see what's going on.
I used Laravel's auth scaffold to login, then created a route that would generate an autologin link, log out the user and redirect them to the /home
page. When visiting that the redirect works as expected and logs the user back in.
Route::get('autologin/{token}', ['as' => 'autologin', 'uses' => '\Watson\Autologin\AutologinController@autologin']);
Route::get('/test', function () {
$user = auth()->user();
$link = Autologin::to($user, '/home');
auth()->logout();
return redirect()->away($link);
});