laravel集成github登录

现在很网站都集成了常见的登录,比较方便

比如qq登录,微信扫码登录,以及github登录

今天介绍下如何github登录

先自己注册一个github账号,登陆成功后点击右上角的头像选择其中的settings,然后打开页面,再点击Applications,接着再点击Developer settings,再选择OAuth Apps
点击Register a new application,根据要求填入数据,点击下方Register application即可生成我们想要的Client Id 和Client Secret

![](https://www.yuanchengzhushou.cn/static/image/github.jpg)

执行`composer require "overtrue/laravel-socialite:~2.0"`来安装扩展

将以下代码加入config/app.php中

```
'providers' => [
// Other service providers...
Overtrue\LaravelSocialite\ServiceProvider::class,
],
```

然后将对下代码加入config/services.php中

```
'github' => [
'client_id' => '0f0447920f3882ff6d8a',
'client_secret' => 'ff3f78396b635bf7b5154137***05b0d9e933dce',
'redirect' => 'http://test.api-game.shzhanmeng.com/api/github/login',
],
```

添加路由

```
Route::get('/github', 'API\TestController@index');
Route::get('/github/login', 'API\TestController@handleProviderCallback');
```

创建`controller`

```
redirect();
}

/**
¦* 从GitHub获取认证用户信息
¦*/
public function handleProviderCallback()
{
¦ $user = Socialite::driver('github')->user();
¦ dd($user);
}
}
```

    A+
发布日期:2021年01月01日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: