All Projects → felix-dumit → Pfuser Digits

felix-dumit / Pfuser Digits

Authenticate Parse Users using Twitter Digits

Projects that are alternatives of or similar to Pfuser Digits

Python Patch
Library to parse and apply unified diffs
Stars: ✭ 65 (-14.47%)
Mutual labels:  parse
Firebase Stripe
Headless Stripe Payments Using Firebase Functions
Stars: ✭ 72 (-5.26%)
Mutual labels:  firebase
Parse Ms
Parse milliseconds into an object
Stars: ✭ 74 (-2.63%)
Mutual labels:  parse
Firebaseauth Android
Firebase Authentication code guideline for Android developer
Stars: ✭ 67 (-11.84%)
Mutual labels:  firebase
Mock Cloud Firestore
Mock library for Cloud Firestore
Stars: ✭ 69 (-9.21%)
Mutual labels:  firebase
Vuejsfire Hackathon Starter
Hackathon starter kit based on vue.js and Firebase
Stars: ✭ 73 (-3.95%)
Mutual labels:  firebase
Rgviperchat
An iOS chat app written following a VIPER architecture and BDD
Stars: ✭ 65 (-14.47%)
Mutual labels:  firebase
Whatsapp Clone React Native
The goal of this project is to build an Whatsapp exactly like the original application, but using React Native & Redux | Firebase
Stars: ✭ 76 (+0%)
Mutual labels:  firebase
The forge
Our groundbreaking, lightning fast PWA CLI tool
Stars: ✭ 70 (-7.89%)
Mutual labels:  firebase
Parser
Generate a JSON documentation for a SFC Vue component. Contribute: https://gitlab.com/vuedoc/parser#contribute
Stars: ✭ 74 (-2.63%)
Mutual labels:  parse
Pushraven
A simple Java library to interface with Firebase Cloud Messaging (FCM) API. Pushraven allows you to push notifications to clients in very few lines of code.
Stars: ✭ 67 (-11.84%)
Mutual labels:  firebase
Parse Sdk Js
The JavaScript SDK for the Parse Platform
Stars: ✭ 1,158 (+1423.68%)
Mutual labels:  parse
Experimental Extensions
🧪 A laboratory for new extensions created by Firebase
Stars: ✭ 73 (-3.95%)
Mutual labels:  firebase
Instadart Flutter Instagram Clone
Instagram Clone App Using - Dart, Flutter, Firebase
Stars: ✭ 66 (-13.16%)
Mutual labels:  firebase
Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+11984.21%)
Mutual labels:  parse
Habito
Simple habit tracker app for Android
Stars: ✭ 65 (-14.47%)
Mutual labels:  firebase
Angular Redux Ngrx Examples
Sample projects with Angular (4.x) + Angular CLI + ngrx (Redux) + Firebase
Stars: ✭ 73 (-3.95%)
Mutual labels:  firebase
Game Music Player
All your music are belong to us
Stars: ✭ 76 (+0%)
Mutual labels:  firebase
Firebase Admin Interop
Firebase Admin Interop Library for Dart
Stars: ✭ 75 (-1.32%)
Mutual labels:  firebase
Integrify
🤝 Enforce referential and data integrity in Cloud Firestore using triggers
Stars: ✭ 74 (-2.63%)
Mutual labels:  firebase

PFUser-Digits

A way to authenticate Parse Users using the Twitter Digits API

Make sure you setup your project with Digits and with Parse

**Digits -> Firebase Migration

Steps:

1) Official Migration:

https://docs.fabric.io/apple/digits/apple-migration.html

2) Parse-Server changes:

Copy the firebaseServiceAccountKey.json from firebase into your server root folder, then add these before creating ParseServer:

process.env.FIREBASE_SERVICE_ACCOUNT_KEY = `${__dirname}/firebaseServiceAccountKey.json`;
process.env.FIREBASE_DATABASE_URL = "https://api-project-SOME_NUMBER.firebaseio.com";

Add this adapter when creating ParseServer:

oauth: {
    firebase: require("parse-server-firebase-auth-adapter")
}

Existing users with expired token

If there are any existing users, which are no longer logged into your digits session and you'd like to migrate them to a firebase session (you can't do it through the app if they're not logged in), you will need to manually add the following field in their mongoDB user instance:

"_auth_data_firebase" : {
   "id" : "COPY_THEIR_DIGITS_ID_HERE", 
   "access_token": "invalid"
}
You can run this script in mongoShell
users = db.getCollection("_User")

results = users.find({
  "_auth_data_twitter": {"$exists": true},
  "_auth_data_firebase": {"$exists": false}
 }).toArray()

results.forEach(function(e,i) { 
  d = {
    $set: {"_auth_data_firebase": {"id": e["_auth_data_twitter"]["id"], "access_token": "invalid"}} 
  } 
  users.update(e, d)
  print(e["_id"]) 
})

3) iOS Changes

This assumes you have already succesfully integrated Firebase into your project, as per the official migration guide. Make sure you have these pods installed:

pod "Fabric"
pod "Digits"
pod "Firebase/Core"
pod "Firebase/Auth"
pod "FirebaseUI/Phone"
pod "DigitsMigrationHelper"

Add the files "PFUser+Firebase.{h,m}" to your project.

Initialization (after you setup parse):

[PFUser enableFirebaseLogin];
[FIRApp configure];

Call this if your user is logged in (through digits):

[[User currentUser] tryMigrateDigitsSessionWithConsumerKey:@"KEY" consumerSecret:@"SECRET"];

Call these instead of the digits methods:

[User loginWithFirebaseInBackground];
[[User currentUser] linkWithFirebaseInBackground];

Installation

Add the files "PFUser+Digits.{h,m}" to your project.

Note: This cannot be a cocoapod at the moment since Digits is a static binary so it cannot be added as a dependency. If anyone knows a workaround please let me know.

Make sure to setup the twitter oauth when starting your parse server:

var api = new ParseServer({
    ...
    oauth: {
        twitter: {
            consumer_key: "CONSUMERKEY",
            consumer_secret: "CONSUMERSECRET"
        },
        facebook: {
            appIds: "FACEBOOK"
        }
    }
});

Parse.com version

If you are still using the Parse.com hosted server, you should use the old version of this repo, which required you to add extra cloud-code as well, it is still available under this branch: parse-hosted

Login with Digits

When you setup parse, you also need to call:

[PFUser enableDigitsLogin];

To use just call the function which will trigger the Digits sign-in flow and when succeded, will authenticate or create a new user on Parse.

You may call using blocks:

[PFUser loginWithDigitsInBackground:^(PFUser *user, NSError *error) {
    if(!error){
      // do something with user
    }
}];

Or Using Bolts:

[[PFUser loginWithDigitsInBackground] continueWithBlock: ^id (BFTask *task) {
    if(!task.error){
      PFUser *user = task.result;
      // do something with user
    }
}];

Link Existing Account

You can also link an existing account (anonymous or not) with Digits. This works in the same way as linking with Facebook and allows you to later on log back in using the Digits sign-in

[[PFUser currentUser] linkWithDigitsInBackground]; //returns BFTask*

or

[[PFUser currentUser] linkWithDigitsInBackground:^(PFUser* user, NSError* error) {}]; //block callback

Stored properties

After login or link theese digits properties are available for the current user:

-(nullable NSString *)digitsId;
-(nullable NSString *)digitsEmail;
-(nullable NSString *)digitsPhone;

You may wish to copy the digitsEmail to the stored email property on PFUser.

Note: to get the email you must specify DGTAccountFieldsEmail in the configuration as below for instance)

Logout

Even if you logout your Parse User the Digits session is maintained separately, so if you would like to logout of Digits together with Parse, make sure to do something like below when logging out:

[[PFUser logOutInBackground] continueWithSuccessBlock:^(BFTask* task) {
    [Digits sharedInstance] logout];
}];

Customising

For all the previous examples you can pass an DGTAuthenticationConfiguration object. Use it to configure the appearance of the login screen or pass in the phone number to verify. For more information view the Official documentation For example:

DGTAppearance *appearance = [DGTAppearance new];
appearance.backgroundColor = [UIColor whiteColor];
appearance.accentColor = [UIColor defaultLightBlueColor];
appearance.logoImage = [UIImage imageNamed:@"app_icon"];

DGTAuthenticationConfiguration *configuration = [[DGTAuthenticationConfiguration alloc] initWithAccountFields:DGTAccountFieldsEmail];
configuration.appearance = appearance;
configuration.phoneNumber = [User currentUser].phone;
configuration.title = NSLocalizedString(@"phone_login_title", nil);
[PFUser loginWithDigitsInBackgroundWithConfiguration:configuration];

License

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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