Sign In with Phone Number

Digits lets people create an account or sign into your app using nothing but their phone number on iOS and Android. Built using the same global, reliable infrastructure Twitter uses, Digits will verify the user’s phone number with a simple customizable user interface that easily integrates into your app.

Digits extends your existing user/profile database. A successful Digits account creation will return a stable userID to attach or match with your user record, and an oAuth token for the device. A verified phone number is also returned for convenience, but the user’s number may change at any time and should not be used for authentication.

Digits includes web login and signup support, as well as the ability for users to find their friends via their address books.

  • Access your account on Digits website <https://digits.com>
  • Phone numbers are rate limited to normal consumer usage.

Set Up Digits Authentication

Digits offers two ways to kick off the authentication flow: using a pre-configured button, or calling an authentication method from your own button’s tap handler.

Note

Digits authentication workflow screens are translated into the user’s OS language. SMS language is based on the user’s OS language at the time of sign-up.

Using the Pre-Configured Button

In the view controller that will display the button, instantiate the pre-configured button DGTAuthenticateButton after the view is loaded (e.g. in the viewDidLoad method) and provide a completion block to handle the provided session object:

// Objective-C
- (void)viewDidLoad {
    DGTAuthenticateButton *digitsButton = [DGTAuthenticateButton buttonWithAuthenticationCompletion:^(DGTSession *session, NSError *error) {
        // Inspect session/error objects
    }];
    [self.view addSubview:digitsButton];
}
// Swift
override func viewDidLoad() {
    let digitsButton = DGTAuthenticateButton(authenticationCompletion: { (session, error) in
        // Inspect session/error objects
    })
    self.view.addSubview(digitsButton)
}

This will render a button that looks like:

../_images/digits_button.png

Using a Custom Button

In the view controller that displays your custom button, capture a tap event as usual and call the authenticateWithCompletion: method with the completion block that handles the session object:

// Objective-C
- (void)didTapButton {
    [[Digits sharedInstance] authenticateWithCompletion:^(DGTSession *session, NSError *error) {
        // Inspect session/error objects
    }];
}
// Swift
func didTapButton(sender: AnyObject) {
    let digits = Digits.sharedInstance()
    digits.authenticateWithCompletion { (session, error) in
        // Inspect session/error objects
    }
}

Configure the SMS Confirmation Message

After a user enters their phone number they receive an SMS containing a six digit numeric code. This code allows the user to confirm their identity.

The default SMS text is:

Confirmation code: 123456. Enter this code in your app. (Digits by Twitter)

Your can show your app’s name in the SMS by configuring the name property in your Fabric Digits dashboard. With the name set, the SMS text appears as:

Confirmation code: 123456. Enter this code into My Awesome App Name. (Digits by Twitter)

Note

If you’re using Twitter API keys for an existing app generated on apps.twitter.com, set the app’s name through the apps.twitter.com dashboard.

Providing a Phone Number

Digits exposes an API to allow configuration options such as a default phone number to be passed into the authentication flow. Use -authenticateWithViewController:configuration:completion: and include a phone number on the passed configuration object, with optional country code. Digits will attempt to parse out the country code and prepopulate both the country selector and phone number field. Note: the ‘+’ character is required for country code parsing:

// Objective-C
- (void)didTapButton {
    Digits *digits = [Digits sharedInstance];
    DGTAuthenticationConfiguration *configuration = [[DGTAuthenticationConfiguration alloc] initWithAccountFields:DGTAccountFieldsDefaultOptionMask];
    configuration.phoneNumber = @"+345555555555";
    [digits authenticateWithViewController:nil configuration:configuration completion:^(DGTSession *newSession, NSError *error){
        // Country selector will be set to Spain and phone number field will be set to 5555555555
    }];
}
// Swift
func didTapButton(sender: AnyObject) {
    let digits = Digits.sharedInstance()
    let configuration = DGTAuthenticationConfiguration(accountFields: .DefaultOptionMask)
    configuration.phoneNumber = "+345555555555"
    digits.authenticateWithViewController(nil, configuration: configuration) { session, error in
        // Country selector will be set to Spain and phone number field will be set to 5555555555
    }
}

Prefilling the Country Code

Digits allows prefilling of just the country code field if there’s a default country that makes sense for your app. By default, the country picker uses the user’s locale in determining which country to use. This can be changed by launching Digits with -authenticateWithViewController:configuration:completion: and including only the country code in the configuration object.

// Objective-C
- (void)didTapButton {
    Digits *digits = [Digits sharedInstance];
    DGTAuthenticationConfiguration *configuration = [[DGTAuthenticationConfiguration alloc] initWithAccountFields:DGTAccountFieldsDefaultOptionMask];
    configuration.phoneNumber = @"+34";
    [digits authenticateWithViewController:nil configuration:configuration completion:^(DGTSession *newSession, NSError *error){
        // Country selector will be set to Spain
    }];
}
// Swift
func didTapButton(sender: AnyObject) {
    let digits = Digits.sharedInstance()
    let configuration = DGTAuthenticationConfiguration(accountFields: .DefaultOptionMask)
    configuration.phoneNumber = "+34"
    digits.authenticateWithViewController(nil, configuration: configuration) { session, error in
        // Country selector will be set to Spain
    }
}

Access Email Addresses

Digits can be configured to collect the user’s email address as an additional step after a successful phone number authentication.

Initialize the DGTAuthenticationConfiguration class with the DGTAccountFieldsEmail account field. Pass this instance into the Digits authenticateWithViewController:configuration::completion: method to show the email screen.

// Objective-C
DGTAuthenticationConfiguration *configuration = [[DGTAuthenticationConfiguration alloc] initWithAccountFields:DGTAccountFieldsEmail];
configuration.title = @"Login to Digits";
Digits *digits = [Digits sharedInstance];
[digits authenticateWithViewController:nil configuration:configuration completion:^(DGTSession *session, NSError *error) {
    // Inspect session to access the email address of the user
}];
// Swift
let configuration = DGTAuthenticationConfiguration(accountFields: .Email)
configuration.title = "Login to Digits"
let digits = Digits.sharedInstance()
digits.authenticateWithViewController(nil, configuration: configuration) { session, error in
    // Inspect session to access the email address of the user
}

Email Verification

The user’s email address is now available on the DGTSession object returned in the authentication callback. Also included is whether or not the email address is verified. Check out the emailAddress and emailAddressIsVerified properties.

After the user submits the email screen, they will receive an email from Digits asking to confirm their email address. Whether or not the email address is verified is available via the session update delegate and also from your backend via the OAuth Echo endpoint.

Alternative Navigation Flows

UINavigationController

By default, Digits launches with its view controllers in a modal popup over your app’s content. It might make sense for an app to include Digits within a Navigation controller, perhaps if Digits is one of multiple steps in a signup flow. Digits is able to push its authentication flow onto a navigation controller and finish by pushing another provided view controller once the flow has finished.

Using your existing UINavigationController instance, call -[Digits authenticateWithNavigationViewController:phoneNumber:digitsAppearance:title:completionViewController:. The completionViewController is the view controller that will be pushed onto the navigation stack when the Digits flow is completed.

// Objective-C
- (void)didTapButton {
    Digits *digits = [Digits sharedInstance];
    DGTAuthenticationConfiguration *configuration = [[DGTAuthenticationConfiguration alloc] initWithAccountFields:DGTAccountFieldsDefaultOptionMask];
    configuration.phoneNumber = @"+345555555555";
    [digits authenticateWithNavigationViewController:navigationController configuration:configuration completionViewController:completionViewController];
}
// Swift
func didTapButton(sender: AnyObject) {
    let digits = Digits.sharedInstance()
    let configuration = DGTAuthenticationConfiguration(accountFields: .DefaultOptionMask)
    configuration.phoneNumber = "+345555555555"
    digits.authenticateWithNavigationViewController(navigationController, configuration:configuration, completionViewController:completionViewController)
}