Home

Awesome

react-apple-signin-auth

 Apple signin for React using the official Apple JS SDK

<a href="https://npmjs.com/package/react-apple-signin-auth"> <img src="https://img.shields.io/npm/v/react-apple-signin-auth.svg"></img> <img src="https://img.shields.io/npm/dt/react-apple-signin-auth.svg"></img> </a> <a href="https://codecov.io/gh/A-Tokyo/react-apple-signin-auth"> <img src="https://img.shields.io/codecov/c/github/a-tokyo/react-apple-signin-auth.svg"></img> </a> <a href="https://twitter.com/intent/follow?screen_name=ahmad_tokyo"><img src="https://img.shields.io/twitter/follow/ahmad_tokyo.svg?label=Follow%20@ahmad_tokyo" alt="Follow @ahmad_tokyo"></img></a>

Checkout the demo for a quick start!

<a href="https://a-tokyo.github.io/react-apple-signin-auth"> <img src="https://i.imgur.com/Z8avh0K.png"></img> </a>

Prerequisites

  1. You should be enrolled in Apple Developer Program.
  2. Please have a look at Apple documentation related to "Sign in with Apple" feature.
  3. You should create App ID and Service ID in your Apple Developer Account.
  4. You should generate private key for your Service ID in your Apple Developer Account.

Apple Signin Setup

Deatiled confuguration instructions can be found at blog post and Apple docs and official apple docs for webpage signin.

Installation

npm i react-apple-signin-auth

OR

yarn add react-apple-signin-auth

Usage

Checkout the demo for a quick start!

import AppleSignin from 'react-apple-signin-auth';

/** Apple Signin button */
const MyAppleSigninButton = () => (
  <AppleSignin
    /** Auth options passed to AppleID.auth.init() */
    authOptions={{
      /** Client ID - eg: 'com.example.com' */
      clientId: 'com.example.web',
      /** Requested scopes, seperated by spaces - eg: 'email name' */
      scope: 'email name',
      /** Apple's redirectURI - must be one of the URIs you added to the serviceID - the undocumented trick in apple docs is that you should call auth from a page that is listed as a redirectURI, localhost fails */
      redirectURI: 'https://example.com',
      /** State string that is returned with the apple response */
      state: 'state',
      /** Nonce */
      nonce: 'nonce',
      /** Uses popup auth instead of redirection */
      usePopup: ${authOptions.usePopup},
    }} // REQUIRED
    /** General props */
    uiType="dark"
    /** className */
    className="apple-auth-btn"
    /** Removes default style tag */
    noDefaultStyle={false}
    /** Allows to change the button's children, eg: for changing the button text */
    buttonExtraChildren="Continue with Apple"
    /** Extra controlling props */
    /** Called upon signin success in case authOptions.usePopup = true -- which means auth is handled client side */
    onSuccess={(response) => console.log(response)} // default = undefined
    /** Called upon signin error */
    onError={(error) => console.error(error)} // default = undefined
    /** Skips loading the apple script if true */
    skipScript={false} // default = undefined
    /** Apple image props */
    iconProp={{ style: { marginTop: '10px' } }} // default = undefined
    /** render function - called with all props - can be used to fully customize the UI by rendering your own component  */
    render={(props) => <button {...props}>My Custom Button</button>}
  />
);

export default MyAppleSigninButton;
Note about the response's user object

onSuccess response object will contain the user object on the first time attempt only. Meaning if you make another signIn attempt for the same account you will not get the user object.

Raw JS functionality

a module called appleAuthHelpers is also exported to allow you to use the functionality without using the UI or relying on React. This works with any kind of frontend JS, eg: react, vue, etc... Note that you need to load the apple script yourself.

Server-side authentication (nodeJS backend)

Another library exists for server/backend support for Apple signin apple-signin-auth

Usage

Further resources:

Related Projects

Contributing

Pull requests are highly appreciated! For major changes, please open an issue first to discuss what you would like to change.

Getting Started