This repository was archived by the owner on Aug 22, 2026. It is now read-only.
forked from flh/plugin-openidc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_dependencies.php
More file actions
199 lines (174 loc) · 5.71 KB
/
Copy path_dependencies.php
File metadata and controls
199 lines (174 loc) · 5.71 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
declare(strict_types=1);
/**
* OpenID Connect plugin for Galette
*
* PHP version 7
*
* This file is part of 'OpenID Connect plugin for Galette'.
*
* OpenID Connect Plugin for Galette is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenID Connect Plugin for Galette is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with OpenID Connect Plugin for Galette. If not, see
* <http://www.gnu.org/licenses/>.
*
* @category Plugins
* @package OpenID Connect plugin for Galette
*
* @author Manuel Hervouet <manuelh78dev@ik.me>
* @author Florian Hatat <github@hatat.me>
* @copyright Manuel Hervouet (c) 2021
* @copyright Florian Hatat (c) 2022
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0
*/
use Defuse\Crypto\Key;
use GaletteOpenIDC\Repositories\AccessTokenRepository;
use GaletteOpenIDC\Repositories\AuthCodeRepository;
use GaletteOpenIDC\Repositories\ClientRepository;
use GaletteOpenIDC\Repositories\RefreshTokenRepository;
use GaletteOpenIDC\Repositories\ScopeRepository;
use GaletteOpenIDC\Repositories\UserRepository;
use GaletteOpenIDC\Repositories\ClaimRepository;
use GaletteOpenIDC\Tools\Config;
use GaletteOpenIDC\Tools\Debug as Debug;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Grant\RefreshTokenGrant;
use League\OAuth2\Server\ResourceServer;
use Idaas\OpenID\CryptKey;
use Psr\Container\ContainerInterface;
use Idaas\OpenID\Grant\AuthCodeGrant;
use Idaas\OpenID\Grant\ImplicitGrant;
use Idaas\OpenID\RequestTypes\AuthenticationRequest;
use Idaas\OpenID\ResponseTypes\BearerTokenResponse;
use Idaas\OpenID\Session;
use Idaas\OpenID\UserInfo;
/*if (OPENIDC_LOG) {
Debug::init();
}*/
$container = $app->getContainer();
$container->set(
Config::class,
static function (ContainerInterface $container) {
return new GaletteOpenIDC\Tools\Config(OPENIDC_CONFIGPATH . '/config.yml');
},
);
$container->set(
ClaimRepository::class,
static function(ContainerInterface $container) {
return new ClaimRepository();
},
);
$container->set(
AccessTokenRepository::class,
static function(ContainerInterface $container) {
return new AccessTokenRepository($container);
},
);
$container->get(
ClientRepository::class,
static function(ContainerInterface $container) {
return new ClientRepository($container);
},
);
$container->get(
ScopeRepository::class,
static function(ContainerInterface $container) {
return new ScopeRepository();
},
);
$container->set(
AuthorizationServer::class,
function (ContainerInterface $container) {
$conf = $container->get(Config::class);
$encryptionKey = $conf->get('global.encryption_key');
// Load private key
$privateKeyPath = 'file://' . OPENIDC_CONFIGPATH . '/private.key';
$privateKey = new CryptKey($privateKeyPath);
$privateKey->setKid('signing key');
// Setup the authorization server
$server = new AuthorizationServer(
// instance of ClientRepositoryInterface
$container->get(ClientRepository::class),
// instance of AccessTokenRepositoryInterface
$container->get(AccessTokenRepository::class),
// instance of ScopeRepositoryInterface
$container->get(ScopeRepository::class),
// private signing key
$privateKey,
// encryption key
Key::loadFromAsciiSafeString($encryptionKey),
// Custom BearerTokenResponse for OpenID Connect
new BearerTokenResponse,
);
$refreshTokenRepository = new RefreshTokenRepository();
$claimRepository = $container->get(ClaimRepository::class);
$authCodeGrant = new AuthCodeGrant(
new AuthCodeRepository(),
// instance of RefreshTokenRepositoryInterface
$refreshTokenRepository,
$claimRepository,
new Session,
new DateInterval('PT10M'),
new DateInterval('PT10M'),
);
$authCodeGrant->setIssuer('https://' . $_SERVER['HTTP_HOST']);
// Enable the password grant on the server
// with a token TTL of 1 hour
$server->enableGrantType(
$authCodeGrant,
// access tokens will expire after 1 hour
new DateInterval('PT1H'),
);
$userRepository = new UserRepository($container); // instance of UserRepositoryInterface
$implicitGrant = new ImplicitGrant(
$userRepository,
$claimRepository,
new DateInterval('PT10M'),
new DateInterval('PT10M')
);
$implicitGrant->setIssuer('https://' . $_SERVER['HTTP_HOST']);
$server->enableGrantType($implicitGrant, new DateInterval('PT1H'));
$rt_grant = new RefreshTokenGrant($refreshTokenRepository);
// new refresh tokens will expire after 1 month
$rt_grant->setRefreshTokenTTL(new DateInterval('P1M'));
// Enable the refresh token grant on the server
$server->enableGrantType(
$rt_grant,
// new access tokens will expire after an hour
new DateInterval('PT1H'),
);
return $server;
},
);
$container->set(
ResourceServer::class,
static function (ContainerInterface $container) {
$publicKeyPath = 'file://' . OPENIDC_CONFIGPATH . '/public.key';
$publicKey = new CryptKey($publicKeyPath);
$publicKey->setKid('signing key');
return new ResourceServer(
$container->get(AccessTokenRepository::class),
$publicKey,
);
},
);
$container->set(
UserInfo::class,
static function (ContainerInterface $container) {
return new UserInfo(
new UserRepository($container),
$container->get(AccessTokenRepository::class),
$container->get(ResourceServer::class),
$container->get(ClaimRepository::class),
);
},
);