down2323 2018-02-02 21:21
浏览 57
已采纳

使用Laravel Socialite进行社交网络身份验证的安全性

I am using the Socialite for a social network authentication in Laravel App. I wanted to add registration using social networks, without possibility to use the classic registration method byentering username and password. Currently, I decided to create a User model which contains name and username, that is used for uathorization and separate tables in db for each social network that contain user_id and id from the social network as PK.

When the system receives the user's id in chosen social network, it checks the appropriate table for that id and if it exists there - get's the user id and authenticates user to the system. If not - adds there and also authenticates.

The function that handles the response from the social network:

public function handleProviderCallback($social)
{
    $userSocial = Socialite::driver($social)->user();

    $registeredUser = DB::table($social.'_accounts')->find($userSocial->id);

    if(!empty($registeredUser)) {
        Auth::loginUsingId($registeredUser->user_id);
    }else{
        $user = new User;
        $user->name = $userSocial->name;
        $user->username = 'user2222'; //will be implementer in future
        $user->avatar = $userSocial->avatar;
        $user->save();

        DB::table($social.'_accounts')->insert(['id' => $userSocial->id, 'user_id' => $user->id ]);
        Auth::loginUsingId($user->id);
    }

        return redirect()->action('HomeController@index');
}

The question is about security, may you explain me whether that solution is quite secure or not? I mean the authentication without password, just in case receiving the user's id from the social network. Can that query from the social network be forged to get an access to smb'a account?

  • 写回答

1条回答 默认 最新

  • dongmin1166 2018-02-02 21:26
    关注

    Since you are using oAuth this is the preferred method of user authentication.

    Since you are using Socialite it automatically checks against the provider to prevent fake requests being fired. Thus yes this would be considered safe.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀