create-prisma-php-app 1.11.18 → 1.11.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Lib/Auth/Auth.php +45 -24
- package/package.json +1 -1
|
@@ -213,38 +213,59 @@ class Auth
|
|
|
213
213
|
// Save user data to the database
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
private function findProvider(array $providers, string $type): ?object
|
|
217
|
+
{
|
|
218
|
+
foreach ($providers as $provider) {
|
|
219
|
+
if ($provider instanceof $type) {
|
|
220
|
+
return $provider;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public function authProviders(...$providers)
|
|
217
227
|
{
|
|
218
228
|
global $isGet, $dynamicRouteParams;
|
|
219
229
|
|
|
220
|
-
if ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH])
|
|
221
|
-
$
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
230
|
+
if ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
231
|
+
foreach ($providers as $provider) {
|
|
232
|
+
if ($provider instanceof GithubProvider && in_array('github', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
233
|
+
$githubAuthUrl = "https://github.com/login/oauth/authorize?scope=user:email%20read:user&client_id={$provider->clientId}";
|
|
234
|
+
redirect($githubAuthUrl);
|
|
235
|
+
} elseif ($provider instanceof GoogleProvider && in_array('google', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
236
|
+
$googleAuthUrl = "https://accounts.google.com/o/oauth2/v2/auth?"
|
|
237
|
+
. "scope=" . urlencode('email profile') . "&"
|
|
238
|
+
. "response_type=code&"
|
|
239
|
+
. "client_id=" . urlencode($provider->clientId) . "&"
|
|
240
|
+
. "redirect_uri=" . urlencode($provider->redirectUri);
|
|
241
|
+
redirect($googleAuthUrl);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
231
244
|
}
|
|
232
245
|
|
|
233
246
|
$authCode = Validator::validateString($_GET['code'] ?? '');
|
|
234
247
|
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
248
|
+
if ($isGet && in_array('callback', $dynamicRouteParams[self::PPHPAUTH]) && isset($authCode)) {
|
|
249
|
+
if (in_array('github', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
250
|
+
$provider = $this->findProvider($providers, GithubProvider::class);
|
|
251
|
+
|
|
252
|
+
if (!$provider) {
|
|
253
|
+
exit("Error occurred. Please try again.");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return $this->githubProvider($provider, $authCode);
|
|
257
|
+
} elseif (in_array('google', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
258
|
+
$provider = $this->findProvider($providers, GoogleProvider::class);
|
|
259
|
+
|
|
260
|
+
if (!$provider) {
|
|
261
|
+
exit("Error occurred. Please try again.");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return $this->googleProvider($provider, $authCode);
|
|
265
|
+
}
|
|
247
266
|
}
|
|
267
|
+
|
|
268
|
+
exit("Error occurred. Please try again.");
|
|
248
269
|
}
|
|
249
270
|
|
|
250
271
|
private function githubProvider(GithubProvider $githubProvider, string $authCode)
|