Giter VIP home page Giter VIP logo

example-socialite-apple's Introduction

Laravel Socialite Apple Example

Installation

Configure apple sign in, a good starting point is the blog of Aaron Parecki

Add the following variables in your .env file:

SOCIAL_CLIENTID_APPLE=YOUR_APPLE_CLIENT_ID

SOCIAL_CLIENT_SECRET_APPLE=Client_secret

SOCIAL_REDIRECT_APPLE=/social-auth/handle/apple/

The following points should be considered in order to use the apple provider in socialite:

Email only in the first handle

You only get the email address in the first login of the user. You should save the email address (user->email) and the apple identifier (sub) (user->id). The second time you use this identifier to find the user in your laravel applications. See SocialAuthController -> getHandleCallback

Handle a post request of the authorization token

Add your authorization handle post request in the VerifyCsrfToken, in this example:

 protected $except = [
        '/social-auth/handle/apple'
    ];

Client Secret

Refresh the client_secret apple key each six months (write a automatic cronjob)

A cronjob example with client.rb:

#!/usr/bin/env bash

source /usr/local/rvm/environments/ruby-2.6.3

cd /your_path_apple_sign_in/

ruby client.rb > apple_client.txt

/bin/cp -f apple_client.txt /your_laravel_path/storage/apple/apple_client.txt

chown your_linux_user/your_linux_group /your_laravel_path/storage/apple/apple_client.txt

Other solution to refresh your client secret, see comment alinmiron

Private email replay

If the user is using his anonymous email-address, a standard email relay (mandrill, sendgrid) is not possible at this moment.

If everything is working

Succesfull login: Save your_apple_identifer as apple_identifier in your db and [email protected] 
user->email, you only get the email once!!), 
for the development you could delete your apple app https://appleid.apple.com/account/manage 
(security ->  to test this again

Troubleshouting

Invalid grant

  • Invalid grant: check that your client_id and client_secret has the same service_id.
  • Timeout

Invalid state exception

  • Initiate the apple request again, state is invalid.

License

The Laravel framework and this example is open-source software licensed under the MIT license.

example-socialite-apple's People

Contributors

theodh avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.