|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acacha\LaravelSocial\Services; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class ConfigureSocialLogin. |
|
7
|
|
|
* |
|
8
|
|
|
* @package Acacha\LaravelSocial\Services |
|
9
|
|
|
*/ |
|
10
|
|
|
abstract class ConfigureSocialLogin |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Laravel console commmand. |
|
14
|
|
|
* |
|
15
|
|
|
* @var |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $command; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Info URL about how to register and Oauth Client. |
|
21
|
|
|
* |
|
22
|
|
|
* @return mixed |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract protected function infoURL(); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Social network name. |
|
28
|
|
|
* |
|
29
|
|
|
* @return mixed |
|
30
|
|
|
*/ |
|
31
|
|
|
abstract protected function name(); |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param \Illuminate\Console\Command $command |
|
35
|
|
|
* @return $this |
|
36
|
|
|
*/ |
|
37
|
|
|
public function command(\Illuminate\Console\Command $command) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->command = $command; |
|
40
|
|
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Run social network configuration. |
|
45
|
|
|
*/ |
|
46
|
|
|
public function execute() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->showInfoAboutSocialNetwork(); |
|
49
|
|
|
$this->obtainOAuthClientData(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Show info about social network |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function showInfoAboutSocialNetwork() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->command->info('Configuring social network ' . ucfirst($this->name()) . '...'); |
|
58
|
|
|
$this->command->info('Please register a new OAuth app for ' . ucfirst($this->name()) . |
|
59
|
|
|
'. Go to URL <question>' . $this->infoURL() . '</question>'); |
|
60
|
|
|
$this->showOptionalAdditionalInfo(); |
|
61
|
|
|
$this->command->info('Then ask the following questions:'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Obtain OAuth client data. |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function obtainOAuthClientData() |
|
68
|
|
|
{ |
|
69
|
|
|
$oauth = resolve(\Acacha\LaravelSocial\Services\OAuthApp::class); |
|
70
|
|
|
$oauth->setId(trim($this->command->ask('OAuth client id?'))); |
|
71
|
|
|
$oauth->setSecret(trim($this->command->ask('OAuth client secret?'))); |
|
72
|
|
|
$oauth->setRedirectUrl(trim($this->command->ask('OAuth client redirect URL?', $this->getDefaultRedirectURL()))); |
|
73
|
|
|
|
|
74
|
|
|
$service = resolve(\Acacha\LaravelSocial\Services\LaravelSocialiteService::class); |
|
75
|
|
|
$service->app($oauth)->social(strtolower($this->name()))->handle(); |
|
76
|
|
|
$this->command->info(ucfirst($this->name()) . ' added to config/services.php file'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Default Redirect URL. |
|
81
|
|
|
* |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function getDefaultRedirectURL() |
|
85
|
|
|
{ |
|
86
|
|
|
return 'http://localhost:8080/auth/' . strtolower($this->name()) . '/callback'; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Show (if needed) additional info. |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function showOptionalAdditionalInfo() |
|
93
|
|
|
{ |
|
94
|
|
|
return; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|