├── .gitignore ├── README.md ├── app └── android │ └── DigitsApp │ ├── .gitignore │ ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── digits │ │ │ └── digitsapp │ │ │ └── ApplicationTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ └── app.properties.template │ │ ├── java │ │ └── digits │ │ │ └── digitsapp │ │ │ ├── MainActivity.java │ │ │ ├── MyInterface.java │ │ │ └── PhoneInfo.java │ │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── proguard-com.digits.sdk.android.digits.txt │ └── settings.gradle ├── assets ├── dynamo_db.png ├── identity_pool.png └── lambda_testing.png ├── lambda ├── client.html ├── server.js └── server_event.json └── screenshot.png /.gitignore: -------------------------------------------------------------------------------- 1 | #built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Windows thumbnail db 19 | Thumbs.db 20 | 21 | # OSX files 22 | .DS_Store 23 | 24 | # Eclipse project files 25 | .classpath 26 | .project 27 | 28 | # Android Studio 29 | *.iml 30 | .idea 31 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 32 | .gradle 33 | build/ 34 | 35 | *app.properties 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Twitter Digits with Amazon Web Services 2 | 3 | This sample code demonstrates using Twitter Digits to enable phone-based authentication, and using the AWS platform -- Cognito, Lambda and DynamoDB -- to provide simple and scalable back-end services for your mobile application. 4 | 5 | 6 | 7 | Once you have this sample running, you can imagine other possible phone-based use cases, including: 8 | 9 | - Deliver notifications or offers to user via Amazon SMS 10 | - Connect with existing CRM solution to pre-populate user experience (Frequent Flyer status, Rewards memberships, etc.) 11 | - Track in-app activity for personalization or A/B testing 12 | - Protect against bot/spam abuse through phone verification 13 | 14 | Requirements 15 | --- 16 | 17 | The requirements needed to use this sample code are: 18 | 19 | 1. Download and install Android Studio (http://developer.android.com/tools/studio/index.html) 20 | 2. Download and install Fabric (https://fabric.io) 21 | 3. Amazon Web Services account (http://aws.amazon.com/) 22 | 23 | Steps to run sample code 24 | --- 25 | 26 | Follow the below steps to setup the Android App and the back-end AWS services: 27 | 28 | 1. Set up Digits for Android App (details below) 29 | 2. Set up AWS Cognito (details below) 30 | 3. Create an AWS Dynamo instance (details below) 31 | 32 | As a final note, ensure that all AWS instances are located in US-East, so that they can make full use of Cognito and can connect to one another. 33 | 34 | 35 | Setting up Digits/Getting token key & secret 36 | --- 37 | 38 | 1. Via Fabric, install the Digits Kit into your Android app 39 | 2. Log into your Fabric dashboard (https://fabric.io/dashboard) 40 | 3. Select your app from the top drop-down and then click on the Digits icon to the left 41 | 4. Your key/secret should appear on the page to the right 42 | 43 | Once you have your token/secret, you want to add them into a properties file that the app reads. Copy the `app.properties.template` file into `app.properties` and add them under TWITTER_KEY and TWITTER_SECRET. 44 | 45 | 46 | Setting up AWS Cognito/creating an identity pool 47 | --- 48 | 49 | In order to get your access key and secret for the HTML example, follow the below instructions: 50 | 51 | 1. Log into the Amazon Cognito console (https://console.aws.amazon.com/cognito) 52 | 2. Click on "Create new Identity pool" 53 | 3. Specify a name for the pool and also specify your Twitter key/secret 54 | 55 | Below is a screenshot of the identity pool creation page, for your reference: 56 | 57 | 58 | 59 | You'll now want to add this into the `app.properties` file in the AWS_IDENTITY_POOL_ID property. 60 | 61 | Create an AWS DynamoDB instance 62 | --- 63 | 64 | To store and retrieve records on the server, the Lambda service connects to a DynamoDB instance. To easily create a store, follow the below instrutions: 65 | 66 | 1. Log into the Amazon DynamoDB console (https://console.aws.amazon.com/dynamodb) 67 | 2. Click on the "Create Table" button 68 | 3. Specify the table name as "digits-with-lambda" 69 | 4. Specify the Primary Key Type as "Hash" with Hash Name as "phoneNumber" and String type 70 | 71 | 72 | After your app is fully deployed and running, you can also view the saved entries via the "Explore Table" button on the DynamoDB console. You should see records that look like the following: 73 | 74 | 75 | 76 | Create an AWS Lambda service 77 | --- 78 | 79 | To create a scalable and simple Lambda service for this code, following the below steps: 80 | 81 | 1. Log into the Amazon Lambda console (https://console.aws.amazon.com/lambda) 82 | 2. Click on the "Create a Lambda function" button 83 | 3. Specify the Name as "digitsLogin" 84 | 4. Specify the Runtime to be Node.js 85 | 5. Copy the code from `lambda/server.js` into the code area on the page 86 | 6. Specify the Handler as "index.handler" 87 | 7. For Role, choose a "Basic with Dynamo" role (you may need to create a new one) 88 | 8. Save the service 89 | 90 | To test that your service works properly, you can open the digitsLogin detail page and use the "Sample event" + Invoke button to execute the code. The sample JSON for testing is located in `lambda/server_event.json` file. The test area should like the below: 91 | 92 | 93 | 94 | 95 | Additional reading 96 | --- 97 | 98 | The following documents serve as additional information on the Amazon platform and Twitter Digits. 99 | 100 | - [Amazon Cognito](http://aws.amazon.com/cognito/) 101 | - [Announcing Twitter and Digits Support for Amazon Cognito](http://mobile.awsblog.com/post/Tx398OODXZXXAMZ/Announcing-Twitter-and-Digits-Support-for-Amazon-Cognito) 102 | - [Twitter Digits](http://get.digits.com/) 103 | - [Amazon Lambda](http://aws.amazon.com/lambda/details/) 104 | - [The future is now, and it's using AWS Lambda](http://lg.io/2015/05/16/the-future-is-now-and-its-using-aws-lambda.html) 105 | -------------------------------------------------------------------------------- /app/android/DigitsApp/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { url 'https://maven.fabric.io/public' } 4 | } 5 | 6 | dependencies { 7 | classpath 'io.fabric.tools:gradle:1.+' 8 | } 9 | } 10 | apply plugin: 'com.android.application' 11 | apply plugin: 'io.fabric' 12 | 13 | repositories { 14 | maven { url 'https://maven.fabric.io/public' } 15 | } 16 | 17 | 18 | android { 19 | compileSdkVersion 21 20 | buildToolsVersion "22.0.1" 21 | 22 | defaultConfig { 23 | applicationId "digits.digitsapp" 24 | minSdkVersion 21 25 | targetSdkVersion 22 26 | versionCode 1 27 | versionName "1.0" 28 | } 29 | buildTypes { 30 | release { 31 | minifyEnabled false 32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 33 | } 34 | } 35 | } 36 | 37 | dependencies { 38 | compile fileTree(dir: 'libs', include: ['*.jar']) 39 | compile 'com.amazonaws:aws-android-sdk-core:2.+' 40 | compile 'com.amazonaws:aws-android-sdk-cognito:2.+' 41 | compile 'com.amazonaws:aws-android-sdk-s3:2.+' 42 | compile 'com.amazonaws:aws-android-sdk-ddb:2.+' 43 | compile 'com.amazonaws:aws-android-sdk-lambda:2.2.+' 44 | 45 | // Crashlytics Kit 46 | compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') { 47 | transitive = true 48 | } 49 | 50 | // Twitter Kit 51 | compile('com.twitter.sdk.android:twitter:1.6.0@aar') { 52 | transitive = true 53 | } 54 | 55 | // Digits Kit 56 | compile('com.digits.sdk.android:digits:1.6.1@aar') { 57 | transitive = true; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /opt/twitter/opt/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/androidTest/java/digits/digitsapp/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package digits.digitsapp; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/assets/app.properties.template: -------------------------------------------------------------------------------- 1 | # Get your Twitter key/secret by following the below steps: 2 | # 3 | # 1.) Download and install Fabric (https://fabric.io) 4 | # 2.) Install the Digits Kit into your Android app 5 | # 3.) Log into your Fabric dashboard (https://fabric.io/dashboard) 6 | # 4.) Select your app from the top drop-down and then click on the Digits icon to the left 7 | # 5.) Your key/secret should appear on the page to the right 8 | TWITTER_KEY=YOUR_TWITTER_KEY_HERE 9 | TWITTER_SECRET=YOUR_TWITTER_SECRET_HERE 10 | 11 | # Get your AWS identity pool by following the below steps: 12 | # 13 | # 1.) Log into the Amazon Cognito console (https://console.aws.amazon.com/cognito) 14 | # 2.) Click on "Create new Identity pool" 15 | # 3.) Specify a name for the pool and also specify your Twitter key/secret 16 | AWS_IDENTITY_POOL_ID=YOUR_AWS_IDENTITY_POOL_HERE -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/java/digits/digitsapp/MainActivity.java: -------------------------------------------------------------------------------- 1 | package digits.digitsapp; 2 | 3 | import android.app.Activity; 4 | import android.content.res.AssetManager; 5 | import android.content.res.Resources; 6 | import android.os.AsyncTask; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | import android.view.Menu; 10 | import android.view.MenuItem; 11 | import android.widget.Toast; 12 | 13 | import io.fabric.sdk.android.Fabric; 14 | 15 | import com.amazonaws.auth.CognitoCachingCredentialsProvider; 16 | import com.amazonaws.regions.Regions; 17 | import com.amazonaws.auth.AWSCredentialsProvider; 18 | import com.amazonaws.mobileconnectors.lambdainvoker.LambdaFunctionException; 19 | import com.amazonaws.mobileconnectors.lambdainvoker.LambdaInvokerFactory; 20 | 21 | import com.digits.sdk.android.AuthCallback; 22 | import com.digits.sdk.android.Digits; 23 | import com.digits.sdk.android.DigitsAuthButton; 24 | import com.digits.sdk.android.DigitsException; 25 | import com.digits.sdk.android.DigitsSession; 26 | import com.twitter.sdk.android.Twitter; 27 | import com.twitter.sdk.android.core.TwitterAuthConfig; 28 | import com.twitter.sdk.android.core.TwitterAuthToken; 29 | import com.twitter.sdk.android.core.TwitterCore; 30 | import com.twitter.sdk.android.core.identity.TwitterLoginButton; 31 | 32 | import com.twitter.sdk.android.core.Callback; 33 | import com.twitter.sdk.android.core.Result; 34 | import com.twitter.sdk.android.core.TwitterException; 35 | import com.twitter.sdk.android.core.TwitterSession; 36 | import com.twitter.sdk.android.core.identity.TwitterLoginButton; 37 | 38 | import java.io.IOException; 39 | import java.io.InputStream; 40 | import java.util.HashMap; 41 | import java.util.Map; 42 | import java.util.Properties; 43 | 44 | public class MainActivity extends Activity { 45 | 46 | static Properties properties = null; 47 | 48 | // Get your Twitter key/secret by following the below steps: 49 | // 50 | // 1.) Download and install Fabric (https://fabric.io) 51 | // 2.) Install the Digits Kit into your Android app 52 | // 3.) Log into your Fabric dashboard (https://fabric.io/dashboard) 53 | // 4.) Select your app from the top drop-down and then click on the Digits icon to the left 54 | // 5.) Your key/secret should appear on the page to the right 55 | // 56 | // Note: Your consumer key and secret should be obfuscated in your source code before shipping. 57 | // Note: moved these into a properties file; please see getProperty() 58 | // private static final String TWITTER_KEY = "YOUR_TWITTER_KEY_HERE"; 59 | // private static final String TWITTER_SECRET = "YOUR_TWITTER_SECRET_HERE"; 60 | 61 | // Get your AWS identity pool by following the below steps: 62 | // 63 | // 1.) Log into the Amazon Cognito console (https://console.aws.amazon.com/cognito) 64 | // 2.) Click on "Create new Identity pool" 65 | // 3.) Specify a name for the pool and also specify your Twitter key/secret 66 | // 67 | // Note: moved these into a properties file; please see getProperty() 68 | // private static final String AWS_IDENTITY_POOL_ID = "YOUR_AWS_IDENTITY_POOL_ID"; 69 | 70 | private static final String TAG = "DIGITS_SAMPLE"; 71 | 72 | @Override 73 | protected void onCreate(Bundle savedInstanceState) { 74 | 75 | super.onCreate(savedInstanceState); 76 | 77 | TwitterAuthConfig authConfig = new TwitterAuthConfig(getProperty("TWITTER_KEY"), getProperty("TWITTER_SECRET")); 78 | Fabric.with(this, new TwitterCore(authConfig), new Digits()); 79 | setContentView(R.layout.activity_main); 80 | 81 | final CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider( 82 | this, // get the context for the current activity 83 | getProperty("AWS_IDENTITY_POOL_ID"), // your identity pool id 84 | Regions.US_EAST_1 //Region 85 | ); 86 | 87 | // Create a digits button and callback 88 | DigitsAuthButton digitsButton = (DigitsAuthButton) findViewById(R.id.auth_button); 89 | digitsButton.setCallback(new AuthCallback() { 90 | 91 | @Override 92 | public void success(DigitsSession session, String phoneNumber) { 93 | Log.v(TAG, "DIGITS SUCCESSFUL authentication"); 94 | TwitterAuthToken authToken = (TwitterAuthToken)session.getAuthToken(); 95 | String value = authToken.token + ";" + authToken.secret; 96 | Map logins = new HashMap(); 97 | logins.put("www.digits.com", value); 98 | 99 | // Store the data in Amazon Cognito 100 | credentialsProvider.setLogins(logins); 101 | 102 | // Send the data to Amazon Lambda 103 | // 1. Setup a PhoneInfo (containing relevant information) 104 | PhoneInfo ph = new PhoneInfo(); 105 | ph.setPhoneNumber(phoneNumber); 106 | ph.setId(session.getId()); 107 | ph.setAccessToken(authToken.token); 108 | ph.setAccessTokenSecret(authToken.secret); 109 | 110 | // 2. Send the data to the function sendData to parse the request asynchronously 111 | sendData(ph); 112 | 113 | } 114 | 115 | @Override 116 | public void failure(DigitsException exception) { 117 | // Do something on failure 118 | Log.d(TAG, "Oops Digits issue"); 119 | } 120 | }); 121 | 122 | // Create a Twitter login button and callback 123 | TwitterLoginButton twitterButton = (TwitterLoginButton) findViewById(R.id.login_button); 124 | twitterButton.setCallback(new Callback() { 125 | 126 | @Override 127 | public void success(Result result) { 128 | 129 | Log.v(TAG, "TWITTER SUCCESSFUL authentication"); 130 | 131 | TwitterSession session = result.data; 132 | TwitterAuthToken authToken = session.getAuthToken(); 133 | String value = authToken.token + ";" + authToken.secret; 134 | Map logins = new HashMap(); 135 | logins.put("api.twitter.com", value); 136 | 137 | // Store the data in Amazon Cognito 138 | credentialsProvider.setLogins(logins); 139 | 140 | // Send the data to Amazon Lambda 141 | // 1. Setup a PhoneInfo (containing relevant information) 142 | PhoneInfo ph = new PhoneInfo(); 143 | ph.setUserName(session.getUserName()); 144 | ph.setUserId(session.getUserId()); 145 | ph.setId(session.getId()); 146 | ph.setAccessToken(authToken.token); 147 | ph.setAccessTokenSecret(authToken.secret); 148 | 149 | // 2. Send the data to the function sendData to parse the request asynchronously 150 | sendData(ph); 151 | 152 | } 153 | 154 | @Override 155 | public void failure(TwitterException exception) { 156 | // Do something on failure 157 | Log.d(TAG, "Oops Twitter issue"); 158 | } 159 | }); 160 | } 161 | 162 | private void sendData(PhoneInfo phoneInfo){ 163 | 164 | Log.d(TAG, "LAMBDA: Sending Data"); 165 | // 1. Setup a provider to allow posting to Amazon Lambda 166 | final AWSCredentialsProvider provider = new CognitoCachingCredentialsProvider( 167 | this, 168 | getProperty("AWS_IDENTITY_POOL_ID"), 169 | Regions.US_EAST_1); 170 | 171 | // 2. Setup a LambdaInvoker Factory w/ provider data 172 | LambdaInvokerFactory factory = new LambdaInvokerFactory( 173 | this.getApplicationContext(), 174 | Regions.US_EAST_1, 175 | provider); 176 | 177 | // 3. Create an interface (see MyInterface) 178 | final MyInterface myInterface = factory.build(MyInterface.class); 179 | 180 | // 3. Send the data to the "digitsLogin" function on Amazon Lambda. 181 | // Note: Make sure it is done in background, not in main thread. 182 | new AsyncTask() { 183 | 184 | @Override 185 | protected String doInBackground(PhoneInfo... params) { 186 | // invoke "echo" method. In case it fails, it will throw a 187 | // LambdaFunctionException. 188 | try { 189 | Log.d(TAG, "LAMBDA: Attempting to send data"); 190 | return myInterface.digitsLogin(params[0]); 191 | } catch (LambdaFunctionException lfe) { 192 | Log.e("amazon", "Failed to invoke echo", lfe); 193 | return null; 194 | } 195 | } 196 | 197 | @Override 198 | protected void onPostExecute(String result) { 199 | if (result == null) { 200 | Log.d(TAG, "LAMBDA: Response from request is null"); 201 | return; 202 | } else { 203 | Log.d(TAG, "LAMBDA: Received result"); 204 | Log.d(TAG, result); 205 | } 206 | // Do a toast 207 | Log.d(TAG, "LAMBDA: Making Toast with result"); 208 | Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show(); 209 | 210 | } 211 | }.execute(phoneInfo); 212 | 213 | } 214 | @Override 215 | public boolean onCreateOptionsMenu(Menu menu) { 216 | // Inflate the menu; this adds items to the action bar if it is present. 217 | getMenuInflater().inflate(R.menu.menu_main, menu); 218 | return true; 219 | } 220 | 221 | @Override 222 | public boolean onOptionsItemSelected(MenuItem item) { 223 | // Handle action bar item clicks here. The action bar will 224 | // automatically handle clicks on the Home/Up button, so long 225 | // as you specify a parent activity in AndroidManifest.xml. 226 | int id = item.getItemId(); 227 | 228 | //noinspection SimplifiableIfStatement 229 | if (id == R.id.action_logout) { 230 | 231 | // Clear session on logout 232 | Digits.getSessionManager().clearActiveSession(); 233 | Twitter.getSessionManager().clearActiveSession(); 234 | 235 | } else if (id == R.id.action_settings) { 236 | return true; 237 | } 238 | 239 | return super.onOptionsItemSelected(item); 240 | } 241 | 242 | public String getProperty(String key) { 243 | 244 | try { 245 | if (properties == null) { 246 | properties = new Properties(); 247 | InputStream inputStream = 248 | this.getClass().getClassLoader().getResourceAsStream("assets/app.properties"); 249 | properties.load(inputStream); 250 | } 251 | return properties.getProperty(key); 252 | } catch (IOException e){ 253 | Log.d(TAG, "Error reading properties file: " + e.toString()); 254 | return null; 255 | } 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/java/digits/digitsapp/MyInterface.java: -------------------------------------------------------------------------------- 1 | package digits.digitsapp; 2 | 3 | import android.provider.ContactsContract; 4 | 5 | import com.amazonaws.mobileconnectors.lambdainvoker.LambdaFunction; 6 | 7 | /* 8 | * A holder for lambda functions 9 | */ 10 | public interface MyInterface { 11 | 12 | /** 13 | * Invoke lambda function "echo". The function name is the method name 14 | */ 15 | @LambdaFunction 16 | String digitsLogin(PhoneInfo phoneInfo); 17 | 18 | /** 19 | * Invoke lambda function "echo". The functionName in the annotation 20 | * overrides the default which is the method name 21 | */ 22 | @LambdaFunction(functionName = "digitsLogin") 23 | void noDigitsLogin(PhoneInfo phoneInfo); 24 | } -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/java/digits/digitsapp/PhoneInfo.java: -------------------------------------------------------------------------------- 1 | package digits.digitsapp; 2 | 3 | /** 4 | * Created by gjones on 7/6/15. 5 | */ 6 | 7 | public class PhoneInfo { 8 | 9 | private String phoneNumber; 10 | private long id; 11 | private String accessToken; 12 | private String accessTokenSecret; 13 | private String userName; 14 | private long userId; 15 | 16 | public PhoneInfo() { 17 | } 18 | 19 | public PhoneInfo(String phoneNumber, long id, String accessToken, String accessTokenSecret, String userName, long userId) { 20 | this.phoneNumber = phoneNumber; 21 | this.id = id; 22 | this.accessToken = accessToken; 23 | this.accessTokenSecret = accessTokenSecret; 24 | this.userName = userName; 25 | this.userId = userId; 26 | } 27 | 28 | // phoneNumber 29 | public String getPhoneNumber() { 30 | return phoneNumber; 31 | } 32 | 33 | public void setPhoneNumber(String phoneNumber) { 34 | this.phoneNumber = phoneNumber; 35 | } 36 | 37 | // id 38 | public long getId() { 39 | return id; 40 | } 41 | 42 | public void setId(long id) { 43 | this.id = id; 44 | } 45 | 46 | // accessToken 47 | public String getAccessToken() { 48 | return accessToken; 49 | } 50 | 51 | public void setAccessToken(String accessToken) { 52 | this.accessToken = accessToken; 53 | } 54 | 55 | // accessTokenSecret 56 | public String getAccessTokenSecret() { 57 | return accessTokenSecret; 58 | } 59 | 60 | public void setAccessTokenSecret(String accessTokenSecret) { 61 | this.accessTokenSecret = accessTokenSecret; 62 | } 63 | 64 | public String getUserName() { 65 | return userName; 66 | } 67 | 68 | public void setUserName(String userName) { 69 | this.userName = userName; 70 | } 71 | 72 | public long getUserId() { 73 | return userId; 74 | } 75 | 76 | public void setUserId(long userId) { 77 | this.userId = userId; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 15 | 16 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 7 | 8 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/app/android/DigitsApp/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/app/android/DigitsApp/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/app/android/DigitsApp/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/app/android/DigitsApp/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DigitsApp 3 | 4 | Hello world! 5 | Settings 6 | Log out 7 | 8 | -------------------------------------------------------------------------------- /app/android/DigitsApp/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/android/DigitsApp/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/android/DigitsApp/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/android/DigitsApp/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/app/android/DigitsApp/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/android/DigitsApp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /app/android/DigitsApp/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /app/android/DigitsApp/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/android/DigitsApp/proguard-com.digits.sdk.android.digits.txt: -------------------------------------------------------------------------------- 1 | # Twitter Core proguard configuration 2 | # '-include' this file in your proguard config 3 | # Autogenerated file -- Do not modify 4 | 5 | #Proguard Config for when AppCompat is not a dependency 6 | -dontwarn com.digits.sdk.android.*ActionBarActivity 7 | 8 | # retrofit specific 9 | -dontwarn com.squareup.okhttp.** 10 | -dontwarn com.google.appengine.api.urlfetch.** 11 | -dontwarn rx.** 12 | -dontwarn retrofit.** 13 | -keepattributes Signature 14 | -keepattributes *Annotation* 15 | -keep class com.squareup.okhttp.** { *; } 16 | -keep interface com.squareup.okhttp.** { *; } 17 | -keep class retrofit.** { *; } 18 | -keepclasseswithmembers class * { 19 | @retrofit.http.* ; 20 | } -------------------------------------------------------------------------------- /app/android/DigitsApp/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /assets/dynamo_db.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/assets/dynamo_db.png -------------------------------------------------------------------------------- /assets/identity_pool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/assets/identity_pool.png -------------------------------------------------------------------------------- /assets/lambda_testing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/assets/lambda_testing.png -------------------------------------------------------------------------------- /lambda/client.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 27 | 28 | 29 | 30 | Test Lambda Client. 31 | 32 | 33 | -------------------------------------------------------------------------------- /lambda/server.js: -------------------------------------------------------------------------------- 1 | console.log('Loading event'); 2 | 3 | var AWS = require('aws-sdk'); 4 | var db = new AWS.DynamoDB({params: {TableName: "digits-with-lambda"}}); 5 | 6 | var User = { 7 | 8 | get : function(phoneNumber, callback) { 9 | var query = { 10 | Key: { 11 | phoneNumber: { S: phoneNumber } 12 | } 13 | }; 14 | db.getItem(query, callback); 15 | }, 16 | 17 | insert : function(phoneNumber, id, accessToken, accessTokenSecret, name, status, callback) { 18 | var obj = User.makeObject(phoneNumber, id, accessToken, accessTokenSecret, name, status); 19 | var item = { 20 | Item: obj 21 | }; 22 | db.putItem(item, callback); 23 | }, 24 | 25 | update : function(phoneNumber, id, accessToken, accessTokenSecret, name, status, callback) { 26 | var obj = User.makeObject(phoneNumber, id, accessToken, accessTokenSecret, name, status); 27 | var updates = { 28 | Key: { 29 | phoneNumber: { S: phoneNumber } 30 | }, 31 | AttributeUpdates: obj 32 | }; 33 | 34 | db.updateItem(updates, callback); 35 | }, 36 | 37 | makeObject : function(phoneNumber, id, accessToken, accessTokenSecret, name, status){ 38 | 39 | var obj = { 40 | phoneNumber: phoneNumber, 41 | id: id, 42 | accessToken : accessToken, 43 | accessTokenSecret : accessTokenSecret, 44 | name : name, 45 | status : status 46 | }; 47 | 48 | return Utils.dbWrap(obj); 49 | } 50 | 51 | }; 52 | 53 | var Status = { 54 | SILVER : 'Silver', 55 | GOLD : 'Gold', 56 | PLATINUM : 'Platinum' 57 | }; 58 | 59 | var Response = { 60 | 61 | success : function(context, user, isNewUser){ 62 | console.log('Success: ' + JSON.stringify(user) + " " + isNewUser); 63 | var ending = user.name ? ", " + user.name : ""; 64 | if (isNewUser){ 65 | context.succeed('Thank you for joining our service' + ending + '.'); // Echo back the response 66 | } else { 67 | context.succeed('Thank you for being a '+ user.status +' member' + ending + '.'); // Echo back the response 68 | } 69 | }, 70 | 71 | error : function(context, err){ 72 | console.log('Error: ' + err); 73 | context.succeed('Error in request: ' + err); // Echo back the response 74 | } 75 | 76 | }; 77 | 78 | var Utils = { 79 | 80 | isEmpty : function(obj) { 81 | return Object.keys(obj).length === 0; 82 | }, 83 | 84 | isNumber : function(n) { 85 | return typeof(n) === 'number'; 86 | }, 87 | 88 | dbWrap : function(o){ 89 | var o2 = {} 90 | for (var key in o) { 91 | var val = o[key]; 92 | if (val){ 93 | console.log(key + ": " + val + " " + Utils.isNumber(val)); 94 | if (Utils.isNumber(val)){ 95 | val = {N : val + ""}; 96 | } else { 97 | val = {S : val}; 98 | } 99 | o2[key] = val; 100 | } 101 | } 102 | return o2; 103 | }, 104 | 105 | dbUnwrap : function(o){ 106 | var o2 = {} 107 | for (var key in o) { 108 | if (o.hasOwnProperty(key)) { 109 | var val = o[key]['S'] ? o[key]['S'] : o[key]['N'] 110 | if (val){ 111 | o2[key] = val; 112 | } 113 | } 114 | } 115 | return o2; 116 | }, 117 | } 118 | 119 | exports.handler = function(event, context) { 120 | 121 | console.log('Received event:' + JSON.stringify(event)); 122 | 123 | var phoneNumber = event.phoneNumber; 124 | var id = event.id; 125 | var accessToken = event.accessToken; 126 | var accessTokenSecret = event.accessTokenSecret; 127 | 128 | User.get(phoneNumber, function(err, user) { 129 | console.log("getUser: " + JSON.stringify(err) + " " + JSON.stringify(user)); 130 | if (err) { 131 | Response.error(context, err); 132 | } else { 133 | if (Utils.isEmpty(user)){ 134 | User.insert(phoneNumber, id, accessToken, accessTokenSecret, "", Status.SILVER, function(err, user) { 135 | console.log("saveUser: " + JSON.stringify(err) + " " + JSON.stringify(user)); 136 | if (err) { 137 | Response.error(context, err); 138 | } else { 139 | Response.success(context, Utils.dbUnwrap(user.Item), true); 140 | } 141 | }); 142 | } else { 143 | Response.success(context, Utils.dbUnwrap(user.Item), false); 144 | } 145 | } 146 | }); 147 | 148 | }; -------------------------------------------------------------------------------- /lambda/server_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "phoneNumber": "+14155551212", 3 | "id": 3270513476, 4 | "accessToken": "3270513476-Ln9y7vYIQerdJTYn13pmRpzuEXsQhnFVrLXXXXX", 5 | "accessTokenSecret": "q6r3yA02PAp0CYr40NDH32SLLiIUJo9som0ugy8EXXXXX" 6 | } -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crashlytics/digits-with-aws/5e3ea90bc4ec8cb83a1eaca0323cf8d1c8368fa2/screenshot.png --------------------------------------------------------------------------------