Menu
Amazon Cognito
Developer Guide (Version Last Updated: 07/28/2016)

Twitter/Digits

Android

Amazon Cognito integrates with Twitter and Digits to provide federated authentication for your mobile application users. This section explains how to register and set up your application with Twitter and Digits as an identity provider.

Set Up Twitter/Digits

You will need to integrate the TwitterKit SDK in your application. Twitter offers Fabric as a mechanism for enabling various functionality in your application.

Once you've integrated TwitterKit into your application, you get the following values from the Fabric console:

  • Consumer Key

  • Consumer Secret

You must enter these values in the Amazon Cognito Console to configure your identity pool for Twitter/Digits integration.

Using Twitter

Using the TwitterKit SDK login functionality, we need to simply capture the result of the completion handler and pass the appropriate fields to Amazon Cognito.

Twitter sessions contain two important values:

  • User token

  • User secret

Amazon Cognito expects these values to be stored in a single value in logins with the key api.twitter.com, concatenated with a single semicolon (;) delimiter.

Copy
loginButton = (TwitterLoginButton) findViewById(R.id.login_button); loginButton.setCallback(new Callback<TwitterSession>() { @Override public void success(Result<TwitterSession> result) { TwitterSession session = result.data; TwitterAuthToken authToken = session.getAuthToken(); String value = authToken.token + ";" + authToken.secret; Map<String, String> logins = new HashMap<String, String>(); logins.put("api.twitter.com", value); // Note: This overrides any existing logins credentialsProvider.setLogins(logins); } @Override public void failure(TwitterException exception) { // Do something on failure } });

Using Digits

Digits support is handled through a separate call in the Fabric SDK, but the session returned is essentially the same as with Twitter login. You just need to concatenate the token and secret from the session using a single semicolon (;) delimiter and store in logins with the key of www.digits.com.

Copy
DigitsAuthButton digitsButton = (DigitsAuthButton) findViewById(R.id.auth_button); digitsButton.setCallback(new AuthCallback() { @Override public void success(DigitsSession session, String phoneNumber) { TwitterAuthToken authToken = (TwitterAuthToken) session.getAuthToken(); String value = authToken.token + ";" + authToken.secret; Map<String, String> logins = new HashMap<String, String>(); logins.put("www.digits.com", value); // Note: This overrides any existing logins credentialsProvider.setLogins(logins); } @Override public void failure(DigitsException exception) { // Do something on failure } });

iOS

Amazon Cognito integrates with Twitter and Digits to provide federated authentication for your mobile application users. This section explains how to register and set up your application with Twitter and Digits as an identity provider.

Set Up Twitter/Digits

You will need to integrate the TwitterKit SDK in your application. Twitter offers Fabric as a mechanism for enabling various functionality in your application.

Once you've integrated TwitterKit into your application, you get the following values from the Fabric console:

  • Consumer Key

  • Consumer Secret

You must enter these values in the Amazon Cognito Console to configure your identity pool for Twitter/Digits integration.

Using Twitter

Using the TwitterKit SDK login functionality, we need to simply capture the result of the completion handler and pass the appropriate fields to Amazon Cognito.

Twitter sessions contain two important values:

  • User token

  • User secret

Amazon Cognito expects these values to be stored in a single value in logins with the key api.twitter.com, concatenated with a single semicolon (;) delimiter.

Objective-C

Copy
[[Twitter sharedInstance] logInWithCompletion:^ (TWTRSession *session, NSError *error) { if (session) { NSString value = [NSString stringWithFormat:@"%@;%@", session.authToken, session.authTokenSecret]; // Note: This overrides any existing logins credentialsProvider.logins = @{@"api.twitter.com", value}; } else { NSLog(@"error: %@", [error localizedDescription]); } }];

Swift

Copy
Twitter.sharedInstance().logInWithCompletion { (session, error) -> Void in if (session != nil) { var value = session.authToken + ";" + session.authTokenSecret // Note: This overrides any existing logins credentialsProvider.logins = ["api.twitter.com": value] } else { println("error: (error.localizedDescription)") } }

Using Digits

Digits support is handled through a separate call in the Fabric SDK, but the session returned is essentially the same as with Twitter login. You just need to concatenate the token and secret from the session using a single semicolon (;) delimiter and store in logins with the key of www.digits.com.

Objective-C

Copy
[[Digits sharedInstance] authenticateWithCompletion:^ (DGTSession* session, NSError *error) { if (session) { NSString value = [NSString stringWithFormat:@"%@;%@", session.authToken, session.authTokenSecret]; // Note: This overrides any existing logins credentialsProvider.logins = @{@"www.digits.com", value}; } }];

Swift

Copy
let digits = Digits.sharedInstance() digits.authenticateWithCompletion { (session, error) in if (session != nil) { var value = session.authToken + ";" + session.authTokenSecret // Note: This overrides any existing logins credentialsProvider.logins = ["www.digits.com": value] } }

JavaScript

Amazon Cognito integrates with Twitter and Digits to provide federated authentication for your mobile application users. This section explains how to register and set up your application with Twitter and Digits as an identity provider.

Note

We do not yet have documentation for integrating Twitter/Digits with the JavaScript SDK. To learn how Twitter/Digits integration works with other SDKs, select a different platform.

External Resources

Unity

Amazon Cognito integrates with Twitter and Digits to provide federated authentication for your mobile application users. This section explains how to register and set up your application with Twitter and Digits as an identity provider.

Note

We do not yet have documentation for integrating Twitter/Digits with the Unity SDK. To learn how Twitter/Digits integration works with other SDKs, select a different platform.

External Resources

Xamarin

Twitter integration is not natively supported on the Xamarin platform. Integration currently requires the use of a web view to go through the browser sign in flow. To learn how Twitter/Digits integration works with other SDKs, please select another platform.