All Projects → A-Tokyo → react-apple-signin-auth

A-Tokyo / react-apple-signin-auth

Licence: MIT license
 Apple signin for React using the official Apple JS SDK

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-apple-signin-auth

authorize-me
Authorization with social networks
Stars: ✭ 44 (-24.14%)
Mutual labels:  login, auth, signin
vue-apple-signin
A simple Vue plugin to include an Apple sign-in button into your web app.
Stars: ✭ 19 (-67.24%)
Mutual labels:  login, signin, apple-signin
Nativepopup
Clone of Apple iOS App's feedback popup, and easily customizable.
Stars: ✭ 247 (+325.86%)
Mutual labels:  apple, modal, popup
google-one-tap
Google One Tap Login
Stars: ✭ 37 (-36.21%)
Mutual labels:  login, signin
vue-modal
A customizable, stackable, and lightweight modal component for Vue.
Stars: ✭ 96 (+65.52%)
Mutual labels:  modal, popup
springboot-mongodb-security
Spring Boot, Security, and Data MongoDB Authentication Example
Stars: ✭ 22 (-62.07%)
Mutual labels:  login, signin
hapi-doorkeeper
User authentication for web servers
Stars: ✭ 14 (-75.86%)
Mutual labels:  login, auth
eins-modal
Simple to use modal / alert / dialog / popup. Created with pure JS. No javascript knowledge required! Works on every browser and device! IE9
Stars: ✭ 30 (-48.28%)
Mutual labels:  modal, popup
react-signin-form
Concept for Sign in / Sign Up form
Stars: ✭ 109 (+87.93%)
Mutual labels:  login, signin
EasyFirebase
No description or website provided.
Stars: ✭ 48 (-17.24%)
Mutual labels:  login, auth
lua-resty-feishu-auth
适用于 OpenResty / ngx_lua 的基于飞书组织架构的登录认证
Stars: ✭ 28 (-51.72%)
Mutual labels:  login, auth
react-native-popup
React Native Animated Popup Modal
Stars: ✭ 19 (-67.24%)
Mutual labels:  modal, popup
react-spring-bottom-sheet
Accessible ♿️, Delightful ✨, & Fast 🚀
Stars: ✭ 604 (+941.38%)
Mutual labels:  modal, popup
AppleSignIn
Library for fast an easy way to implement Apple Sign In.
Stars: ✭ 19 (-67.24%)
Mutual labels:  login, signin
identifo
Universal authentication framework for web, created with go
Stars: ✭ 58 (+0%)
Mutual labels:  login, auth
vue-modal
Reusable Modal component, supports own custom HTML, text and classes.
Stars: ✭ 29 (-50%)
Mutual labels:  modal, popup
LSDialogViewController
Custom Dialog for iOS written in Swift
Stars: ✭ 74 (+27.59%)
Mutual labels:  modal, popup
rocket auth
An implementation for an authentication API for Rocket applications.
Stars: ✭ 65 (+12.07%)
Mutual labels:  login, auth
supabase-ui-svelte
Supabase authentication UI for Svelte
Stars: ✭ 83 (+43.1%)
Mutual labels:  login, auth
react-redux-modal-flex
[DEPRECATED] Make easy a modal/popup with Redux
Stars: ✭ 14 (-75.86%)
Mutual labels:  modal, popup

react-apple-signin-auth

 Apple signin for React using the official Apple JS SDK

Follow @ahmad_tokyo

Checkout the demo for a quick start!

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.

  • Importing the apple script:
    // using raw html:
    <script src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js" defer></script>
    
    // OR using react hooks:
    import { useScript, appleAuthHelpers } from 'react-apple-signin-auth';
    
    const myComponent = () => {
      useScript(appleAuthHelpers.APPLE_SCRIPT_SRC);
      // ...
    };
    
    export default myComponent;
  • Using appleAuthHelpers:
    import { appleAuthHelpers } from 'react-apple-signin-auth';
    // OR
    // import appleAuthHelpers from 'react-apple-signin-auth/dist/appleAuthHelpers'; // @unstable - might change with upgrades
    
    /**
     * perform apple signIn operation
     */
    appleAuthHelpers.signIn({
      authOptions: {
        // same as above
      },
      onSuccess: (response) => console.log(response),
      onError: (error) => console.error(error),
    });
    
    // OR
    
    /** promisified version - promise resolves with response on success or undefined on error -- note that this only work with usePopup: true */
    const response = await appleAuthHelpers.signIn({
      authOptions: {
        // same as above
      },
      onError: (error) => console.error(error),
    });
    
    if (response) {
      console.log(response);
    } else {
      console.error('Error performing apple signin.');
    }

Server-side authentication (nodeJS backend)

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

Usage

  • Install the library yarn add apple-signin-auth OR npm i apple-signin-auth
  • Implement JWT verification logic
    const appleSignin = require("apple-signin-auth");
    
    
    const { authorization, user } = req.body;
    
    try {
      const { sub: userAppleId } = await appleSignin.verifyIdToken(
        authorization.id_token, // We need to pass the token that we wish to decode.
        {
          audience: "com.example.web", // client id - The same one we used on the frontend, this is the secret key used for encoding and decoding the token.
          nonce: 'nonce' // nonce - The same one we used on the frontend - OPTIONAL
        }
      );
    } catch (err) {
      // Token is not verified
      console.error(err);
    }

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

  • Clone the repo: git clone https://github.com/a-tokyo/react-apple-signin-auth
  • Install deps: yarn
  • Start webpack development server on localhost:3001: yarn start
  • To run/update the tests locally, run: yarn test -u
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].