zoukankan      html  css  js  c++  java
  • laravel-实现第三方github登录

    1.laravel官方提供的第三方登录

    1.2第三方composer登录参考资料

    链接 链接 链接 链接 中文文档
    packagist 参考博客 参考博客 参考博客 中文文档

    1.3github设置

    找到 OAuth Apps

    2.使用composer安装依赖

    composer require overtrue/socialite
    

    config/services.php中加入配置项

    #需要什么加什么这个扩展包支持好多家的登陆
        'github' => [
            'client_id'     => 'your-app-id',
            'client_secret' => 'your-app-secret',
            'redirect'      => 'http://localhost/socialite/callback.php',#登陆成功后要跳转的地址
        ],
    
        'weibo' => [
            'client_id'     => 'your-app-id',
            'client_secret' => 'your-app-secret',
            'redirect'      => 'http://localhost/socialite/callback.php',
        ],
        'qq' => [
            'client_id'     => 'your-app-id',
            'client_secret' => 'your-app-secret',
            'redirect'      => 'http://localhost/socialite/callback.php',
        ],
    

    路由设计

    Route::any('github','AdminGithubController@login');#增加github登录的功能
    Route::any('github/index','AdminGithubController@index');#增加github登录的功能
    

    controller代码

     protected $config = [
            'github' => [
                'client_id' => 'e32739d55fb6c4fa880a',
                'client_secret' => '7a1e5f5380ea915ed2274dda20e3f24f30c8b24c',
                'redirect' => 'http://127.0.0.1:8000/github/index',
            ],
        ];
      public function login()
        {
            $socialite = new SocialiteManager(config['github']);
            $response = $socialite->driver('github')->redirect();
    
            return $response;// or $response->send();
        }
    
        public function index()
        {
            $socialite = new SocialiteManager(config['github']);
            $user = $socialite->driver('github')->user();
    
    //        $user->getId();        // 1472352
    //        $user->getNickname();  // "overtrue"
    //        $user->getUsername();  // "overtrue"
    //        $user->getName();      // "安正超"
    //        $user->getEmail();     // "anzhengchao@gmail.com"
    //        $user->getProviderName(); // GitHub
            $is_null = User::where('github_email', $user->getEmail())->first();
    
            if (empty($is_null)) {
                $user = User::create(['github_email' => $user->getEmail()]);
                session()->put('user', $is_null);
                return 
    edirect('admin/index');
            } else {
                session()->put('user', $is_null);
                return 
    edirect('admin/index');
            }
        }
    

    curl解决方案
    https://curl.haxx.se/docs/caextract.html
    2.带补充现有未解决的bug

  • 相关阅读:
    php增加自动刷新当前页面
    liunx环境下安装mysql5.7及以上版本
    mysql的主从级联复制的配置
    windowns常用命令
    liunx之使用(mount)挂载技术
    在burpsuite中为什么不能选中设置好的代理?
    c++中向任意目录下写文件
    Hbase——JavaAPI操作笔记
    每周总结(6)(补)
    每周总结(5)
  • 原文地址:https://www.cnblogs.com/yaoliuyang/p/13162081.html
Copyright © 2011-2022 走看看