PHPackages                             lamy/laravel-sign-in-apple - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. lamy/laravel-sign-in-apple

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

lamy/laravel-sign-in-apple
==========================

Laravel package to authenticate users using Sign in with Apple

1.0.0(7mo ago)00MITPHPPHP ^8.2

Since Oct 5Pushed 7mo agoCompare

[ Source](https://github.com/Edouard-LAMY/laravel-sign-in-apple)[ Packagist](https://packagist.org/packages/lamy/laravel-sign-in-apple)[ Docs](https://github.com/Edouard-LAMY/laravel-sign-in-apple)[ RSS](/packages/lamy-laravel-sign-in-apple/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Laravel Sign In with Apple
==========================

[](#laravel-sign-in-with-apple)

\[[![Latest Version on Packagist](https://camo.githubusercontent.com/8b17b0d3629bcc9b516755a4764a0c542afb6dcdd52e4dd0ee81cee44392fe18/68747470733a2f2f7061636b61676973742e6f72672f7061636b616765732f6c616d792f6c61726176656c2d7369676e2d696e2d6170706c65)](https://camo.githubusercontent.com/8b17b0d3629bcc9b516755a4764a0c542afb6dcdd52e4dd0ee81cee44392fe18/68747470733a2f2f7061636b61676973742e6f72672f7061636b616765732f6c616d792f6c61726176656c2d7369676e2d696e2d6170706c65)\]

**Laravel Sign In with Apple** is a simple package that makes it easier to implement **Apple Sign In** using Laravel 12 and Socialite.

It handles Apple-specific configurations, token generation, and user data parsing to provide a smooth authentication flow.

---

🚀 Features
----------

[](#-features)

- Easy integration with Laravel and Socialite
- Automatic `client_secret` generation for Apple
- Secure decoding of Apple tokens
- Simple `.env` configuration
- Fully customizable authentication logic

---

📦 Installation
--------------

[](#-installation)

You can install the package via composer:

```
composer require lamy/laravel-sign-in-apple
```

You can add the configuration apple in config/services.php:

```
php artisan laravel-sign-in-apple:install
```

We also recommend using laravel/socialite and socialiteproviders/apple to automatically manage user resolution and persistence:

```
composer require laravel/socialite socialiteproviders/apple
```

Add Event to AppServiceProvider.php in function boot():

```
use Illuminate\Support\Facades\Event;
use SocialiteProviders\Apple\Provider;
use SocialiteProviders\Manager\SocialiteWasCalled;

Event::listen(function (SocialiteWasCalled $event) {
    $event->extendSocialite('apple', Provider::class);
});
```

⚙️ Apple Developer Configuration
--------------------------------

[](#️-apple-developer-configuration)

### 1. Create an App ID

[](#1-create-an-app-id)

- Go to the [Apple Developer Console](https://developer.apple.com/)
- Create a new App ID: [Create a Bundle ID](https://developer.apple.com/account/resources/identifiers/list/bundleId)
    - **Description**: `example.com App ID`
    - **Bundle ID (explicit)**: `com.example.id`
    - Enable: ✅ **Sign In with Apple**
- Retrieve your **Team ID** (e.g. `123AZ987ZA`)
- Add it to your `.env` file:

```
APPLE_TEAM_ID=123AZ987ZA
```

### 2. Create a Service ID

[](#2-create-a-service-id)

- Go to [Create a Service ID](https://developer.apple.com/account/resources/identifiers/list/serviceId)
- Click **➕ Add**:
    - **Description**: `example.com Service ID`
    - **Identifier**: `com.example.service`
    - Enable: ✅ **Sign In with Apple**
- Click **Configure** under "Sign In with Apple":
    - **Primary App ID**: select the App ID created in step 1
    - **Web Domain**: `example.com` (your website domain)
    - **Return URL**: `https://example.com/auth/callback` (your Laravel route)
- Click **Save**
- Go back and click **Edit** to confirm the config is saved
- Add this to your `.env`:

```
APPLE_CLIENT_ID=com.example.service
```

### 3. Create a Sign In with Apple Key

[](#3-create-a-sign-in-with-apple-key)

- Go to **Create a Key** in the Apple Developer Console
- Click **+ Add**
- Enter a **Key Name** (e.g., Sign In with Apple Key)
- ✅ Enable **Sign In with Apple**
- Select the **Primary App ID** created in step 1
- Click **Continue**, then **Register**
- Click **Download** to get the `.p8` key file (⚠️ this download is only available once)
- Rename the downloaded file from `AuthKey_12345ABCD.p8` to `key.pem` by running:

```
mv AuthKey_12345ABCD.p8 key.pem
```

Place the key.pem file at the root of your Laravel project (same level as your .env)

Add the following to your .env file:

```
APPLE_KEY_ID=12345ABCD
```

### 4. Final .env keys overview

[](#4-final-env-keys-overview)

You should have these keys in your .env file:

```
APPLE_CLIENT_ID=com.example.service
APPLE_CLIENT_SECRET=""
APPLE_TEAM_ID=123AZ987ZA
APPLE_KEY_ID=12345ABCD
```

The APPLE\_CLIENT\_SECRET will be generated later.

### 5. Generate the Client Secret Token

[](#5-generate-the-client-secret-token)

To generate the first client secret token, run the following in artisan tinker:

```
php artisan tinker
```

Then inside tinker:

```
\Lamy\LaravelSignInApple\LaravelSignInApple::generateToken();
```

Copy the generated token and set it in your .env:

```
APPLE_CLIENT_SECRET="your_generated_token_here"
```

### 6. Routing

[](#6-routing)

Add the following routes to your routes/auth.php: ⚠️ Specify the callback name as: apple-callback

```
use App\Http\Controllers\Auth\SocialAuthenticationController;

Route::get('/auth/redirect/apple', [SocialAuthenticationController::class, 'socialRedirect'])->name('auth-social');
Route::post('/auth/callback/apple', [SocialAuthenticationController::class, 'appleCallback'])->name('apple-callback');
```

### 7. Controller Example

[](#7-controller-example)

Here is an example controller to handle the Apple Sign In flow:

```
scopes(['name', 'email'])->redirect();
    }

    public function appleCallback(LaravelSignInApple $signInApple, Request $request)
    {
        $socialUser = $signInApple->decodeAppleToken($request);

        if (property_exists($socialUser, 'success') && $socialUser->success === false) {
            return redirect()->intended('/')->with('error', $socialUser->message);
        }

        return $this->authenticate($socialUser, $request);
    }

    public function authenticate(object $socialUser, Request $request)
    {
        $userExist = User::where("apple_id", $socialUser->getId())->first();
        $redirectTo = '/';

        if ($userExist) {
            Auth::login($userExist);
            $redirectTo = '/home';
        } elseif ($socialUser->getEmail()) {
            $user = User::updateOrCreate(
                ['email'                    => $socialUser->getEmail()],
                [
                    'firstname'             => $socialUser->getName()['firstName'] ?? null,
                    'lastname'              => $socialUser->getName()['lastName'] ?? null,
                    'email'                 => $socialUser->getEmail(),
                    'apple_id'              => $socialUser->getId(),
                    'apple_token'           => $socialUser->token,
                    'apple_refresh_token'   => $socialUser->refreshToken,
                ]
            );

            Auth::login($user);
            $redirectTo = '/home';
        }

        return redirect($redirectTo);
    }
}
```

### 🔐 Token Generation and Apple Authentication

[](#-token-generation-and-apple-authentication)

#### `generateToken()`

[](#generatetoken)

The static method `generateToken()` does **not require any parameters**.

If you've run the installation command:

```
php artisan laravel-sign-in-apple:install
```

and properly set the following environment variables: APPLE\_CLIENT\_ID APPLE\_TEAM\_ID APPLE\_KEY\_ID

Then this method will return a string, which is your APPLE\_CLIENT\_SECRET — you can paste it into your .env file. ℹ️ This token is valid for 6 months. After that, you’ll need to generate a new one and update APPLE\_CLIENT\_SECRET again.

### 🔐 Decode Apple Token Authentication

[](#-decode-apple-token-authentication)

#### `decodeAppleToken(Request $request)`

[](#decodeappletokenrequest-request)

The static method decodeAppleToken() expects an instance of Illuminate\\Http\\Request as a parameter, to handle the callback from Apple.

It will: Extract the authorization code from $request-&gt;input('code') Exchange the authorization code for an access token, Verify the Apple ID token’s signature, Extract user data (ID, email, name) and return a structured object for use in your app.

✅ Returned object structure The returned object provides the following methods and properties:

```
$socialUser->getId();         // string       (Apple user ID)
$socialUser->getEmail();      // string|null  (Apple email)
$socialUser->getName();       // array|null   ['firstName' => ..., 'lastName' => ...]
$socialUser->token;           // string|null  (Apple access token)
$socialUser->refreshToken;    // string|null  (Apple refresh token)
```

⚠️ Errors are silently encapsulated in the returned object using:

```
$socialUser->success = false;
$socialUser->message = 'Error during authentication via Apple.';
```

You can choose to handle these errors manually.

🔒 Security notes The Apple ID token (JWT) is validated against Apple’s public key.

The method uses: firebase/php-jwt phpseclib/phpseclib

to handle cryptographic operations and ensure secure authentication.

⚠️ Handling Missing Name and Email

If a user doesn’t provide name and email during the Apple Sign In, they can: On their iPhone, go to Settings Tap on their Avatar or Name Tap Sign In with Apple Remove the app that was previously authorized

Retry the login flow; Apple will prompt for name and email only once

For more info, see: StackOverflow - Laravel Socialite Apple Sign In no user info

Credits - [Edouard LAMY](https://github.com/)
---------------------------------------------

[](#credits---edouard-lamy)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance64

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

220d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/db799aaa2910ab89be291733465073c35132c9122bd251e741b629df557a563d?d=identicon)[DoudouLamy](/maintainers/DoudouLamy)

---

Top Contributors

[![Edouard-LAMY](https://avatars.githubusercontent.com/u/83162948?v=4)](https://github.com/Edouard-LAMY "Edouard-LAMY (13 commits)")

---

Tags

laravellamylaravel-sign-in-apple

### Embed Badge

![Health badge](/badges/lamy-laravel-sign-in-apple/health.svg)

```
[![Health](https://phpackages.com/badges/lamy-laravel-sign-in-apple/health.svg)](https://phpackages.com/packages/lamy-laravel-sign-in-apple)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k96.9M674](/packages/laravel-socialite)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)[njoguamos/laravel-turnstile

A laravel wrapper for https://developers.cloudflare.com/turnstile/

2315.9k2](/packages/njoguamos-laravel-turnstile)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
