在验证laravel 中 InvalidArgumentException Driver [WeiBo] not supported.
public function weibo() { return Socialite::driver('weibo')->redirect(); // return \Socialite::with('WeiBo')->scopes(array('email'))->redirect(); }
public function callback()
{
/*$code=request('code');
dd($code);*/
$oauthUser = Socialite::driver('weibo')->user();
// dd($oauthUser);
$sina_id = (int)$oauthUser->getId();
$name = $oauthUser->getName();
$nickname = $oauthUser->getNickname();
$email = $oauthUser->getEmail();
$sina_avatar = $oauthUser->getAvatar();
/* //从 Token(OAuth2)中获取用户信息
$token = $oauthUser->token;
$user = Socialite::driver('WeiBo')->userFromToken($token);
dd($user);*/
$where['sina_id'] = $sina_id;
$userDetail = ThirdLogin::where($where)->first();
//若sina_id用户不存在,向third_login表中添加用户信息的同时,向user表中也添加条信息,
//将user信息与third_login,方便前台登录查询
if (empty($userDetail)) {
$user = ThirdLogin::create(compact('sina_id', 'name', 'nickname', 'email', 'sina_avatar'));
$name = $user->nickname;
$avatar = $user->sina_avatar;
$email = $user->email;
$third_id = $user->sina_id;
$password = 0;
User::create(compact('name', 'password', 'email', 'avatar', 'third_id'));
//使用Auth::login(实例,true)授权登录 ,这部分代码不能拿出去优化
$is_user = user::where('third_id', $user->sina_id)->first();
Auth::login($is_user, $remember = false);
if (\Auth::check()) {//授权成功
return \redirect('/posts');
} else {
return \Redirect::back()->withErrors('授权失败');
}
// User::third_login($user);
} else {
$is_user = user::where('third_id', $userDetail->sina_id)->first();
Auth::login($is_user, $remember = false);
if (\Auth::check()) {//授权成功
return \redirect('/posts');
} else {
return \Redirect::back()->withErrors('授权失败');
}
// User::third_login($userDetail);
// return Redirect::back()->withErrors('微博用户'.$userDetail->nickname.'已存在');
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/113007.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...