-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathAppleSignInController.php
More file actions
43 lines (36 loc) · 1.16 KB
/
AppleSignInController.php
File metadata and controls
43 lines (36 loc) · 1.16 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
<?php
namespace GeneaLabs\LaravelSignInWithApple\Http\Controllers;
use GeneaLabs\LaravelSignInWithApple\Events\AppleSignInCallback;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Socialite\Facades\Socialite;
class AppleSignInController extends Controller
{
/**
* Redirect to Apple for authentication.
*/
public function redirect(): RedirectResponse
{
return Socialite::driver('sign-in-with-apple')
->scopes(['name', 'email'])
->redirect();
}
/**
* Handle the callback from Apple.
*
* Dispatches an AppleSignInCallback event with the Socialite user,
* then redirects to a configurable route. Listen for the event
* to persist or process the authenticated user.
*/
public function callback(Request $request): RedirectResponse
{
$user = Socialite::driver('sign-in-with-apple')->user();
AppleSignInCallback::dispatch($user);
$redirect = config(
'services.sign_in_with_apple.routes.callback_redirect',
'/',
);
return redirect()->to($redirect);
}
}