|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SocialiteProviders\Generators\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use SocialiteProviders\Generators\Compilers\Compiler; |
|
7
|
|
|
use SocialiteProviders\Generators\Compilers\OAuth1Compiler; |
|
8
|
|
|
use SocialiteProviders\Generators\Compilers\OAuth2Compiler; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
11
|
|
|
|
|
12
|
|
|
class MakeProviderCommand extends Command |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* The console command name. |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $name = 'make:socialite'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The console command description. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $description = 'Create a new OAuth1 Provider.'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Create a new controller creator command instance. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the console command. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function fire() |
|
40
|
|
|
{ |
|
41
|
|
|
$data = [ |
|
42
|
|
|
'name' => $this->argument('name'), |
|
43
|
|
|
'authorName' => $this->option('author'), |
|
44
|
|
|
'authorMail' => $this->option('email'), |
|
45
|
|
|
'oauthVersion' => $this->option('spec'), |
|
46
|
|
|
'scopes' => $this->option('scopes'), |
|
47
|
|
|
'requestTokenUrl' => $this->option('request_token_url'), |
|
48
|
|
|
'authorizeUrl' => $this->option('authorize_url'), |
|
49
|
|
|
'accessTokenUrl' => $this->option('access_token_url'), |
|
50
|
|
|
'userDetailsUrl' => $this->option('user_details_url'), |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
switch ($this->option('spec')) { |
|
54
|
|
|
case 'oauth1': |
|
55
|
|
|
$compiler = new OAuth1Compiler($data); |
|
56
|
|
|
break; |
|
57
|
|
|
|
|
58
|
|
|
case 'oauth2': |
|
59
|
|
|
$compiler = new OAuth2Compiler($data); |
|
60
|
|
|
break; |
|
61
|
|
|
|
|
62
|
|
|
default: |
|
63
|
|
|
return $this->error('Neither OAuth1 nor OAuth2 was specified.'); |
|
64
|
|
|
break; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$compiler->composer(); |
|
68
|
|
|
$compiler->extendSocialite(); |
|
69
|
|
|
$compiler->provider(); |
|
70
|
|
|
|
|
71
|
|
|
if ($this->option('spec') === 'oauth1') { |
|
72
|
|
|
$compiler->server(); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->addToComposer($compiler); |
|
76
|
|
|
|
|
77
|
|
|
$this->info('Provider generated. Run "composer dumpautoload" and "composer require socialiteproviders/manager" to get started.'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get the console command arguments. |
|
82
|
|
|
* |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function getArguments() |
|
86
|
|
|
{ |
|
87
|
|
|
return [ |
|
88
|
|
|
['name', InputArgument::REQUIRED, 'Name of the provider.'], |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get the console command options. |
|
94
|
|
|
* |
|
95
|
|
|
* @return array |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function getOptions() |
|
98
|
|
|
{ |
|
99
|
|
|
return [ |
|
100
|
|
|
['spec', null, InputOption::VALUE_REQUIRED, 'The OAuth version that should be used.'], |
|
101
|
|
|
['author', null, InputOption::VALUE_REQUIRED, 'The name of the author.'], |
|
102
|
|
|
['email', null, InputOption::VALUE_REQUIRED, 'The email of the author.'], |
|
103
|
|
|
['scopes', null, InputOption::VALUE_OPTIONAL, 'The scopes to be requested.'], |
|
104
|
|
|
['request_token_url', null, InputOption::VALUE_OPTIONAL, 'The Request-Token-Endpoint URL.'], |
|
105
|
|
|
['authorize_url', null, InputOption::VALUE_OPTIONAL, 'The Authorization-Endpoint URL.'], |
|
106
|
|
|
['access_token_url', null, InputOption::VALUE_OPTIONAL, 'The Access-Token-Endpoint URL.'], |
|
107
|
|
|
['user_details_url', null, InputOption::VALUE_OPTIONAL, 'The User-Details-Endpoint URL.'], |
|
108
|
|
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param \SocialiteProviders\Generators\Compilers\Compiler $compiler |
|
113
|
|
|
*/ |
|
114
|
|
|
private function addToComposer(Compiler $compiler) |
|
115
|
|
|
{ |
|
116
|
|
|
$contents = json_decode(file_get_contents($filename = base_path('composer.json')), true); |
|
117
|
|
|
|
|
118
|
|
|
$providerName = $compiler->getContext()->nameStudlyCase(); |
|
119
|
|
|
$contents['autoload']['psr-4']["SocialiteProviders\\$providerName"] = "SocialiteProviders/$providerName/src/"; |
|
120
|
|
|
|
|
121
|
|
|
file_put_contents($filename, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.