-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
170 lines (150 loc) · 5.56 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php namespace Codecycler\SURFconext;
use Codecycler\SURFconext\Classes\Extend\LearnKitDepartments;
use Event;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\Signer;
use Lcobucci\Clock\Clock;
use Lcobucci\JWT\Validator;
use Illuminate\Http\Request;
use System\Classes\PluginBase;
use Lcobucci\Clock\SystemClock;
use Lcobucci\Jose\Parsing\Decoder;
use Lcobucci\JWT\Encoding\JoseEncoder;
use Laravel\Socialite\SocialiteManager;
use Codecycler\SURFconext\Classes\KeysFetcher;
use Codecycler\SURFconext\Classes\TokenStorage;
use Codecycler\SURFconext\Classes\TokenRefresher;
use Codecycler\SURFconext\Components\LoginButton;
use Lcobucci\JWT\Validation\Validator as JWTValidator;
use Codecycler\SURFconext\Classes\Extend\RainLabUser;
use Codecycler\SURFconext\Classes\Contract\JSONGetter;
use Codecycler\SURFconext\Classes\Contract\JSONPoster;
use Codecycler\SURFconext\Classes\Contract\Authenticator;
use Codecycler\SURFconext\Classes\Extend\CodecyclerTeams;
use Laravel\Socialite\Contracts\Factory as SocialiteFactory;
use Codecycler\SURFconext\Classes\Adapter\JSONFetcherAdapter;
use Codecycler\SURFconext\Classes\OIDConnectSocialiteProvider;
use Codecycler\SURFconext\Classes\Adapter\NullAuthenticatorAdapter;
/**
* SURFconext Plugin Information File
*/
class Plugin extends PluginBase
{
public $require = [
'RainLab.User',
];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'SURFconext',
'description' => 'No description provided yet...',
'author' => 'Codecycler',
'icon' => 'icon-leaf'
];
}
/**
* Register method, called when the plugin is first registered.
*
* @return void
*/
public function register()
{
// Setup socialite if not already
if (!isset($this->app[SocialiteFactory::class])) {
$this->app->singleton(SocialiteFactory::class, function ($app) {
return new SocialiteManager($app);
});
}
$this->app->singleton(JSONFetcherAdapter::class, function ($app) {
return new JSONFetcherAdapter();
});
$this->app->singleton(JSONGetter::class, function ($app) {
return $app[JSONFetcherAdapter::class];
});
$this->app->singleton(JSONPoster::class, function ($app) {
return $app[JSONFetcherAdapter::class];
});
$this->app->singleton(Decoder::class, function () {
return new JoseEncoder();
});
$this->app->singleton(Parser::class, function ($app) {
return new Token\Parser($app[Decoder::class]);
});
$this->app->singleton(Validator::class, function () {
return new JWTValidator();
});
$this->app->singleton(Clock::class, function () {
$timezone = new \DateTimeZone("Europe/Amsterdam");
return new SystemClock($timezone);
});
$this->app->singleton(Signer::class, function ($app) {
return new Signer\Rsa\Sha256();
});
$this->app->bind(KeysFetcher::class, function ($app) {
return new KeysFetcher(
$app[\Codecycler\SURFconext\Classes\Contract\JSONGetter::class],
$app['cache.store'],
$app[Decoder::class],
config('codecycler.surfconext::config.keys')
);
});
$this->app->bind(TokenRefresher::class, function ($app) {
return new TokenRefresher(
$app[\Codecycler\SURFconext\Classes\Contract\JSONPoster::class],
$app[TokenStorage::class],
config('codecycler.surfconext::config.client_id'),
config('codecycler.surfconext::config.client_secret'),
config('codecycler.surfconext::config.redirect'),
config('codecycler.surfconext::config.token'),
);
});
$this->app->singleton(Authenticator::class, function () {
return new NullAuthenticatorAdapter();
});
}
public function boot()
{
Event::subscribe(RainLabUser::class);
Event::subscribe(CodecyclerTeams::class);
Event::subscribe(LearnKitDepartments::class);
$socialite = $this->app->make(SocialiteFactory::class);
$socialite->extend('surfconext', function ($app) {
return new OIDConnectSocialiteProvider(
$app[Request::class],
$app[Parser::class],
config('codecycler.surfconext::config.client_id'),
config('codecycler.surfconext::config.client_secret'),
config('codecycler.surfconext::config.redirect'),
config('codecycler.surfconext::config.auth'),
config('codecycler.surfconext::config.token'),
config('codecycler.surfconext::config.introspect'),
);
});
}
public function registerComponents()
{
return [
LoginButton::class => 'SurfLoginButton',
];
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'SURFconext Settings',
'description' => 'Manage SURFconext based settings.',
'category' => 'LMS',
'icon' => 'icon-cog',
'class' => 'Codecycler\SURFconext\Models\Settings',
'order' => 500,
'keywords' => 'lms surfconext surf',
]
];
}
}