Code Monkey home page Code Monkey logo

react-native-apple-authentication-android's Introduction

react-native-apple-authentication-android

Getting started

$ yarn add react-native-apple-authentication-android

android/build.gradle

buildscript {
    dependencies {
+        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
    }
}

Service setup

First, follow Apple's instructions to set up Sign In with Apple in your iOS app and for a web service. It is the web service setup that you'll use from Android, but you need both.

More setup is necessary for backend operations, but the above is all you need to use this library. For more detail, you can read Aaron Parecki's walkthrough, What the Heck is Sign In with Apple?

You should have created:

An App ID
    including the Sign In with Apple capability
A Service ID
    using the App ID as its primary
    mapped to a domain you control
        which Apple has verified
    including at least one Return URL

From this setup, you will need two OAuth arguments to use this library:

A client ID, which you entered as the Identifier field of the Service ID.
A redirect URI, which you entered as the Return URL.

We recommend you use an https:// address for your redirect URI. If you use an http:// address, you may need to include a security configuration to allow cleartext traffic. Although this library should intercept the redirect request, you should regard this as a less secure option. If it's necessary, see the Network security configuration documentation for instructions on setting up a security configuration. Add that file to your Manifest's <application> tag using the attribute android:android:networkSecurityConfig.

Usage

import AppleAuthenticationAndroid, {
  NOT_CONFIGURED_ERROR,
  SIGNIN_CANCELLED_ERROR,
  SIGNIN_FAILED_ERROR,
  ResponseType,
  Scope,
} from "react-native-apple-authentication-android";

// Initialize the module
AppleAuthenticationAndroid.configure({
  clientId: "Your client ID",
  redirectUri: "Your redirect URI",

  // [OPTIONAL]
  // Scope.ALL (DEFAULT) = 'email name'
  // Scope.Email = 'email';
  // Scope.Name = 'name';
  scope: Scope.ALL,

  // [OPTIONAL]
  // ResponseType.ALL (DEFAULT) = 'code id_token';
  // ResponseType.CODE = 'code';
  // ResponseType.ID_TOKEN = 'id_token';
  responseType: ResponseType.ALL,
});

// Sign In with Apple
const signInWithApple = async () => {
  try {
    const response = await AppleAuthenticationAndroid.signIn();
    if (response) {
      const code = response.code; // Present if selected ResponseType.ALL / ResponseType.CODE
      const id_token = response.id_token; // Present if selected ResponseType.ALL / ResponseType.ID_TOKEN
      const user = response.user; // Present when user first logs in using appleid
      console.log("Got auth code", code);
      console.log("Got id_token", id_token);
      console.log("Got user", user);
    }
  } catch (error) {
    if (error && error.message) {
      switch (error.message) {
        case NOT_CONFIGURED_ERROR:
          console.log("AppleAuthenticationAndroid not configured yet.");
          break;
        case SIGNIN_FAILED_ERROR:
          console.log("Apple signin failed.");
          break;
        case SIGNIN_CANCELLED_ERROR:
          console.log("User cancelled apple signin.");
          break;

        default:
          break;
      }
    }
  }
};

Credits

This library is based on https://github.com/willowtreeapps/sign-in-with-apple-button-android. As such, it shares its dependencies and some setup instructions.

react-native-apple-authentication-android's People

Contributors

axxag 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.