PHP code example of rinordreshaj / apple-sign-in

1. Go to this page and download the library: Download rinordreshaj/apple-sign-in library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rinordreshaj / apple-sign-in example snippets




namespace App\Http\Controllers\API\Auth;

use Rinordreshaj\AppleSignIn\AppleSignIn;

class AppleSignInController extends Controller
{
    public function login()
    {
        if(AppleSignIn::verify_signature($request->jwt_token))
        {
            // Authentication verified
            $claims = AppleSignIn::get_token_claims($request->access_token);

            $user = User::where([
                    'apple_identifier' => $claims->sub
                ])
                ->orWhere(["email" => $claims->email])
                ->first();

            if(!$user)
            {
             // ADD user on database if it doesn't exists
                $user = User::create([
                    "apple_identifier" => $claims->sub,
                    "email"            => $claims->email,
                    "first_name"       => $request->first_name,
                    "last_name"        => $request->last_name,
                    "register_source"  => "apple"
                ]);
            // You can return the authenticated user object 
        }
    }
}