• Stars
    star
    280
  • Rank 147,492 (Top 3 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Android library for Sign In with Apple

Sign In with Apple Button for Android

A library for adding Sign In With Apple to Android apps.

CircleCI License MIT Public Yes

How it works

This library includes a SignInWithAppleButton class. You can style the button according to Apple's Human Interface Guidelines.

Apple HIG themed button in black with default corner radius Apple HIG themed button in white with rounder corners Apple HIG themed button in outlined white with even rounder corners

You can add this button to your login screen. When tapped, the button presents Apple's OAuth login flow in a web view. After the user signs in, your callback will receive an authorization code. You can then pass the authorization code to your backend's third party login endpoint.

OAuth flow diagram

Do I need this?

You will find this library useful if both of these statements are true:

  1. Your service has both an Android app and an iOS app.
  2. Your apps include third-party login, like signing in with Google, Facebook, or Twitter.

In June 2019, Apple announced Sign In with Apple, another third-party login provider. They also announced that if an iOS app offers any third-party login options, it will be an App Store requirement to offer Sign In with Apple. This rule would go into effect "later this year" (2019). That is, if you don't add the feature, at some point you won't be able to ship updates to your iOS app.

Obviously Apple does not control Android. But if you have to add a login method to your iOS app, your users will need it on your Android app too. If it isn't supported, your users won't be able to log in if they switch to Android.

We built this library to make it as painless as possible to add Sign In with Apple to your Android app.

Instructions

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.

Installation

Include as a dependency using Gradle:

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.willowtreeapps:signinwithapplebutton:0.3'
}

Snapshot versions are also available.

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

dependencies {
    implementation 'com.willowtreeapps:signinwithapplebutton:0.4-SNAPSHOT'
}

Configuration

Add a SignInWithAppleButton to your login screen's layout.

Configure the button's appearance properties in layout XML:

  • style: Specify a style, "@style/SignInWithAppleButton.Black" (default), "@style/SignInWithAppleButton.White", or "@style/SignInWithAppleButton.WhiteOutline".
  • sign_in_with_apple_button_textType: Specify an enum value, "signInWithApple" (default) or "continueWithApple".
  • sign_in_with_apple_button_cornerRadius: Specify a dimension, like "4dp" (default), "0dp", "8px", etc.

These options are based on the style options from Apple's Human Interface Guidelines.

At runtime, create an instance of SignInWithAppleConfiguration, supplying these values:

  • clientId: Use the client ID value from service setup.
  • redirectUri: Use the redirect URI value from service setup.
  • scope: Specify a space-delimited string of OpenID scopes, like "name email".

According to our understanding of OpenID Connect, the "openid" scope should be included. But at this time of writing, that causes the authentication page to fail to initialize. Beta idiosyncrasies like these are documented in How Sign in with Apple differs from OpenID Connect.

Configure the button with a FragmentManager to present the login interface, the service you created above, and a callback to receive the success/failure/cancel result.

Example

Set up a SignInWithAppleButton via XML:

<com.willowtreeapps.signinwithapplebutton.view.SignInWithAppleButton
    android:id="@+id/sign_in_with_apple_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="@style/SignInWithAppleButton.Black"
    app:sign_in_with_apple_button_textType="signInWithApple"
    app:sign_in_with_apple_button_cornerRadius="4dp" />

In your Activity, create the SignInWithAppleService, then configure the button:

override fun onCreate(savedInstanceState: Bundle?) {
    ...

    val configuration = SignInWithAppleConfiguration(
        clientId = "com.your.client.id.here",
        redirectUri = "https://your-redirect-uri.com/callback",
        scope = "email"
    )

    val signInWithAppleButton = findViewById(R.id.sign_in_with_apple_button)
    signInWithAppleButton.setUpSignInWithAppleOnClick(supportFragmentManager, configuration) { result ->
        when (result) {
            is SignInWithAppleResult.Success -> {
                // Handle success
            }
            is SignInWithAppleResult.Failure -> {
                // Handle failure
            }
            is SignInWithAppleResult.Cancel -> {
                // Handle user cancel
            }
        }
    }
}

If configuring the button from Java, you can supply an implementation of SignInWithAppleCallback instead of a single callback function.

Behavior

When the user taps the button, it will present a web view configured to let the user authorize your service as an OAuth client of their Apple ID. After the user authorizes access, Apple will forward to the redirect URI and include an authorization code. The web view will intercept this request and locate the authorization code.

If the user completes authentication, your callback will receive a SignInWithAppleResult.Success with the authorization code. Your backend endpoint can then phone home to Apple to exchange the authorization code for tokens, completing login.

If instead there is a failure, your callback will receive a SignInWithAppleResult.Failure with the error.

If the user dismisses the authentication screen intentionally, you will receive a SignInWithAppleResult.Cancel.

If you supplied a SignInWithAppleCallback implementation rather than a single callback function, you will instead receive a call to the corresponding callback method.

Sample application

We've included a sample Android app in the sample folder. This app is comparable to Apple's sample project for the iOS Sign In with Apple button.

The sample app demonstrates:

  1. Adding the button and styling it, in activity_sample.xml
  2. Configuring the button with service details and a client, in SampleActivity.onCreate() or SampleJavaActivity.onCreate()
  3. Making use of the authorization code on success, in the callback

You can adjust this sample project with your service configuration and try signing in.

SampleActivity, the Kotlin sample implementation, is launched by the sample app. To view SampleJavaActivity, you would need to update the activity name in the sample app's manifest XML.

Related projects

Roadmap

  • Use a Chrome Custom Tab on Marshmallow and later so users know they are not being phished
    • This will require consuming apps to configure App Links, but it's the Right Way to do it for OAuth security
  • Keep up with changes to Sign In with Apple during beta; 1.0 when the service itself is 1.0
  • Standard Android ripple effect? Material-themed Sign In with Apple button?

Contributing

Contributions are welcome. Please see the Contributing guidelines.

This project has adopted a code of conduct defined by the Contributor Covenant, the same used by the Swift language and countless other open source software teams.

Disclaimer

The Apple logo belongs to Apple. It's included in this library because it's specified in Apple's Human Interface Guidelines. We're using it in good faith according to its intended purpose. As a consumer of this library, please read the HIG and avoid misusing Apple's intellectual property.

More Repositories

1

spruce-android

Spruce Animation Library
Java
3,716
star
2

spruce-ios

Swift library for choreographing animations on the screen.
Swift
3,438
star
3

Hyperion-iOS

In-app design review tool to inspect measurements, attributes, and animations.
Objective-C
2,047
star
4

Hyperion-Android

App Debugging & Inspection Tool for Android
Java
1,946
star
5

assertk

assertions for kotlin inspired by assertj
Kotlin
753
star
6

vocable-android

Vocable for Android
Kotlin
115
star
7

OAK

Library to address common hurdles in Android development
Java
110
star
8

android-instant-apps-demo

Java
108
star
9

fuzzywuzzy-kotlin

Fuzzy string matching for Kotlin (JVM, native, JS, Web Assembly) - port of Fuzzy Wuzzy Python lib
Kotlin
78
star
10

vocable-ios

Vocable AAC for iOS - Empowering people to communicate with care takers and loved ones.
Swift
78
star
11

cordux

Swift
61
star
12

scratch

Easy app data clearing and relaunching
Java
57
star
13

ukor

A Roku build tool with support for build flavors
Brightscript
49
star
14

ouroboros

Infinitely scrolling carousel for tvOS
Swift
48
star
15

wist

A linter for BrightScript
C++
43
star
16

rocute

beautiful ui components for roku development
Brightscript
37
star
17

rootx

Wrap sqlx in even more convenience
Go
37
star
18

PinkyPromise

A tiny Promises library.
Swift
33
star
19

trafficcop

Monitor your Android apps' data usage so you can take action if it's over a threshold.
Java
27
star
20

BlurredVideo-iOS

Applying a blur to a HTTP live stream
Swift
27
star
21

SimpleRecyclerViewDemo

A simple Android application demonstrating the RecyclerView/Adapter/ViewHolder pattern.
Java
26
star
22

react-formable

React Forms
TypeScript
25
star
23

lottie-player

A mac based player for Lottie
Swift
22
star
24

opentest4k

kotlin multiplatform implementation/bindings of opentest4j
Kotlin
20
star
25

android-svg-test

Android SVG sample project to demonstrate OAK's AnimatedSvgView
Java
17
star
26

hello-shared-kotlin

Shared kotlin lib between android and ios
Kotlin
16
star
27

WillowTreeScrollingTabController

Tab based container implementation for iOS written in Swift
Swift
12
star
28

catalyst-slack-service

Unconscious gender bias has been fueling the gender gap for far too long. We’re releasing the #BiasCorrect code in hopes that coders around the world will adapt it for whatever chat-based platforms they use in order to give more people access to this tool for change.
Java
12
star
29

tablediff

Swift
11
star
30

hinoki

A Language Server Protocol implementation for BrightScript
TypeScript
10
star
31

rokul-runnings

Roku Automation, written in TypeScript
TypeScript
10
star
32

wombats-api

Wombats API
Clojure
10
star
33

grove

Swift
8
star
34

WillowTreeReachability

Simple Swift class for monitoring network reachability.
Swift
6
star
35

fastlane-plugin-msbuild

MSBuild / Xamarin actions for Fastlane
Ruby
6
star
36

conductor-mobile

Conductor Mobile is a port of the Conductor Web Framework for iOS and Android
Java
6
star
37

dockertestapp

basic android app for usage in docker
Kotlin
5
star
38

vscode-ide-brightscript

Brightscript support for vscode
TypeScript
5
star
39

Sweetgum

A simple REST client built in C# using Avalonia
C#
5
star
40

palette-vs-the-dress

Java
4
star
41

wombats-web-client

Web Client for Wombats
Clojure
4
star
42

catalyst-bias-correct-service

A bias correction service
Java
4
star
43

acorn

Provides helper functionality for writing code generators (specifically for Go, in Go)
Go
4
star
44

bark

Swift
4
star
45

namegame_ios

The Name Game for iOS
3
star
46

wat-test-project

A bare skeleton for prospective WAT members to pick at.
3
star
47

xambuild

Build Xamarin projects outside of Visual Studio!
Python
3
star
48

intro-to-core-ml

An introduction to Core ML.
Swift
3
star
49

ios-google-home-demo

Swift
3
star
50

IntroiOSExamples

A group of examples that are used for the WillowTree Intro to iOS Course
Swift
3
star
51

atom-ide-brightscript

TypeScript
3
star
52

iot-android-things-robot-arm

Kotlin
2
star
53

namegame_android

2
star
54

Sweetgum.Client

Sweetgum assists in the development and testing of APIs and applications that utilize APIs.
TypeScript
2
star
55

AXComponentKit

Experimental framework for more reliable iOS automation tests
Swift
2
star
56

capwic_event_info

Swift
1
star
57

slacksnax-server

JavaScript
1
star
58

friday-shots

Friday Shots rules, game runner, and results data
Python
1
star
59

battlebots-swift-front-end

A swift framework for building a BattleBots front-end.
Swift
1
star
60

smart-speaker-detector-sample-android

Finds an assortment of smart speakers
Kotlin
1
star
61

android-bootcamp

Sample app for Android bootcamp and associated issue tracking
Java
1
star
62

wombats-ios

iOS Frontend client for Wombats
Swift
1
star
63

namegame-cs

Name Game skeleton project for C#
1
star
64

slacksnax-slackCommand

JavaScript
1
star
65

wta-lighthouse-logger

JavaScript
1
star
66

code-analysis-web

HTML
1
star
67

maple-mosaic

Our in-office Lego wall - scripts for building out the images and printouts.
JavaScript
1
star
68

wombats-documentation

Wombat's API Documentation
JavaScript
1
star