Skip to content

Commit

Permalink
Merge pull request #1 from Kenini1805/debug-laravel-socialite
Browse files Browse the repository at this point in the history
Oauth2 with git hub
  • Loading branch information
Kenini1805 committed Jan 25, 2019
2 parents 7d02379 + 6ebb977 commit 440e9b7
Show file tree
Hide file tree
Showing 26 changed files with 1,049 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,4 +10,5 @@ Homestead.yaml
npm-debug.log
yarn-error.log
.docker
.vscode

4 changes: 4 additions & 0 deletions .idea/blade.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/laravel5.7-with-docker.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

394 changes: 394 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions app/Http/Controllers/Auth/AuthController.php
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Controllers\Auth;

use Auth;
use Socialite;
use App\Models\User;
use App\Http\Controllers\Controller;

class AuthController extends Controller
{
/**
* Redirect the user to the Github authentication page
*
* @return Response
*/
public function redirectToProvider($provider) {
return Socialite::driver($provider)->redirect();
}

/**
* Obtain the user information from Github
*
* @return Response
*/
public function handleProviderCallback($provider)
{
$user = Socialite::driver($provider)->user();
$createdUser = User::firstOrCreate([
'provider' => $provider,
'name' => $user->getName(),
'email' => $user->getEmail(),
'provider_id' => $user->getId(),
]);

// Login với user vừa tạo.
Auth::login($createdUser);

return redirect('/home');
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/RegisterController.php
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers\Auth;

use App\User;
use App\Models\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -59,7 +59,7 @@ protected function validator(array $data)
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
* @return \App\Models\User
*/
protected function create(array $data)
{
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Controllers/HomeController.php
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
}
4 changes: 2 additions & 2 deletions app/User.php → app/Models/User.php
@@ -1,6 +1,6 @@
<?php

namespace App;
namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
Expand All @@ -16,7 +16,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name', 'email', 'password', 'provider', 'provider_id'
];

/**
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -11,6 +11,7 @@
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.7.*",
"laravel/socialite": "^4.0",
"laravel/tinker": "^1.0"
},
"require-dev": {
Expand Down
133 changes: 130 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/app.php
Expand Up @@ -161,6 +161,7 @@
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Laravel\Socialite\SocialiteServiceProvider::class,

/*
* Package Service Providers...
Expand Down Expand Up @@ -223,6 +224,7 @@
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Socialite' => Laravel\Socialite\Facades\Socialite::class,

],

Expand Down
2 changes: 1 addition & 1 deletion config/auth.php
Expand Up @@ -67,7 +67,7 @@
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
'model' => App\Models\User::class,
],

// 'users' => [
Expand Down
8 changes: 7 additions & 1 deletion config/services.php
Expand Up @@ -31,7 +31,7 @@
],

'stripe' => [
'model' => App\User::class,
'model' => App\Models\User::class,
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
'webhook' => [
Expand All @@ -40,4 +40,10 @@
],
],

'github' => [
'client_id' => env('GITHUB_CLIENT_ID'), // Your GitHub Client ID
'client_secret' => env('GITHUB_CLIENT_SECRET'), // Your GitHub Client Secret
'redirect' => env('GITHUB_CALLBACK_URL'),
],

];
2 changes: 1 addition & 1 deletion database/factories/UserFactory.php
Expand Up @@ -13,7 +13,7 @@
|
*/

$factory->define(App\User::class, function (Faker $faker) {
$factory->define(App\Models\User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
Expand Down

0 comments on commit 440e9b7

Please sign in to comment.