Laravel 5 - 无需密码手动登录用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32661305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:22:03  来源:igfitidea点击:

Laravel 5 - Manually logging in a user without password

laravelauthenticationoauthlaravel-5

提问by Omid

I want to login users after authenticating them using OAuth and Google account without entering any password.

我想在不输入任何密码的情况下使用 OAuth 和 Google 帐户对用户进行身份验证后登录用户。

I know Auth::loginfuncton can do such action but I don't know how to get the user instance while they haven't been authenticated yet.

我知道Auth::loginfuncton 可以执行此类操作,但我不知道如何在尚未通过身份验证的情况下获取用户实例。

Is there a way to do that?

有没有办法做到这一点?

回答by alexrussell

You can 'manually' log a user in in two diefferent ways:

您可以通过两种不同的方式“手动”登录用户:

// log user in by ID
Auth::loginUsingId([id of user]);

Or

或者

$user = User::find([id here]);
// or maybe
$user = User::whereUsername([username here])->first();

// and then
Auth::login($user);

See the documentation for authentication.

请参阅有关身份验证的文档