Difficulty:BeginnerLength:ShortLanguages:url-selector#selectionChanged" data-controller="url-selector">EnglishEspañolBahasa IndonesiaPortuguêsPусскийTiếng Việt中文(简体)中文(繁體)About Account KitWhat Is Passwordless Authentication?Passwordless authentication skips using a password for registration or login, Instead, user authentication is confirmed either with a one-time SMS verification code " /> Difficulty:BeginnerLength:ShortLanguages:url-selector#selectionChanged" data-controller="url-selector">EnglishEspañolBahasa IndonesiaPortuguêsPусскийTiếng Việt中文(简体)中文(繁體)About Account KitWhat Is Passwordless Authentication?Passwordless authentication skips using a password for registration or login, Instead, user authentication is confirmed either with a one-time SMS verification code " />

ACCOUNT KIT LÀ GÌ

post-promotion-placement#checkSidebarAdDisplayCondition" data-controller="sticky-ad post-promotion-placement">
Difficulty:BeginnerLength:ShortLanguages:url-selector#selectionChanged" data-controller="url-selector">EnglishEspañolBahasa IndonesiaPortuguêsPусскийTiếng Việt中文(简体)中文(繁體)

About Account Kit

What Is Passwordless Authentication?

Passwordless authentication skips using a password for registration or login. Instead, user authentication is confirmed either with a one-time SMS verification dramrajani.com sent to lớn the user"s phone or a one-time links lớn their tin nhắn address. 

Why Use Passwordless Authentication?

Seamless login and registration process for your users. Keeps access khổng lồ your tiện ích secure, because the user will not reuse passwords or resort khổng lồ easily guessed passwords (such as "password").Avoids taxing your users with the need lớn create & rethành viên chất lượng passwords

In this quick tip tutorial, I will show you how khổng lồ use Account Kit by Facebook for passwordless authentication in your Android tiện ích. Your users will register và login with either their phone number or an email address. Users don"t even need to lớn have sầu a Facebook tài khoản to be authenticated. 

Not only that, but Account Kit is easy khổng lồ implement & saves you from having lớn tediously build a login system. 

*
*
*

How Does Account Kit Work?

The following diagram should make clear how Account Kit works. 

*
*
*

The authentication takes place in a series of exchanges between the user & phầm mềm. First the user initiates the login, perhaps by loading the tiện ích on their phone. Then, a verification dramrajani.com is sent to the user"s SMS, or a one-time link is sent by gmail. After that, if the user enters the validation dramrajani.com or clicks the liên kết, they will be authenticated for the phầm mềm.

Bạn đang xem: Account kit là gì

Another cool feature of Facebook Account Kit is that when your user enters his or her phone number into lớn the phầm mềm, Account Kit will make an attempt to match it with the phone number connected khổng lồ the user"s Facebook protệp tin. If the user is logged into lớn the Android Facebook ứng dụng, và the phone numbers match, Account Kit will skip sending the SMS verification dramrajani.com & the user will be logged in more seamlessly.

Using Account Kit

1. Prerequisites 

To begin lớn use Account Kit, you"ll need:

2. Enable Account Kit 

Go to your tiện ích dashboard, cliông xã the Add Product button, & select Account Kit. Then clichồng the Get Started button khổng lồ add Account Kit. What you will see is the settings configuration for Account Kit. 

*
*
*

3. Declare Dependencies

Add the dependency with the lakiểm tra version of the Account Kit SDK in your build.gradle tệp tin & sync your project. 

repositories jcenter()dependencies compile "com.facebook.android:account-kit-sdk:4.+"

4. Update AndroidManifest.xml 

Add your Facebook ứng dụng ID, Account Kit client token (this is available on the Account Kit settings dashboard), và the INTERNET permission to lớn the AndroidManifest.xml

5. Update the Resource Files 

Include your tiện ích id và Account Kit client token in your strings.xml tệp tin.

YourAPPIdYourAccountKitClientTokenAlso include the Account Kit theme in your styles.

Xem thêm: Simpleblack Là Gì - Từ Điển Anh Việt Semi

xml

6. Initialize the SDK

In your Application class, initialize the SDK (remember to lớn include the android:name in your AndroidManifest.xml).

public class MyApplication extends Application
Override public void onCreate() super.onCreate(); AccountKit.initialize(getApplicationContext());

7. Initiate the Login Flow 

We have lớn write a separate handler for the SMS & email login authentication flows.

For SMS, on line 5, we specify the login type LoginType.PHONE. 

public void onSMSLoginFlow(View view) final Intent intent = new Intent(this, AccountKitActivity.class); AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder = new AccountKitConfiguration.AccountKitConfigurationBuilder( LoginType.PHONE, AccountKitActivity.ResponseType.dramrajani.com); // or .ResponseType.TOKEN // ... persize additional configuration ... intent.putExtra( AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configurationBuilder.build()); startActivityForResult(intent, 101);For tin nhắn, on line 5, we specify the login type LoginType.EMAIL. 

public void onEmailLoginFlow(View view) final Intent intent = new Intent(this, AccountKitActivity.class); AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder = new AccountKitConfiguration.AccountKitConfigurationBuilder( LoginType.EMAIL, AccountKitActivity.ResponseType.dramrajani.com); // or .ResponseType.TOKEN // ... perform additional configuration ... intent.putExtra( AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configurationBuilder.build()); startActivityForResult(intent, 101);

8. Lay Out the Login Screen

Here"s a simple layout for a screen that shows buttons to log in with SMS or email.

9. Handle Responses From the Login Flow

Now when a user attempts to lớn log in, we"ll get a response in the onActivityResult() method. In this method, we can handle successful, cancelled, và failed authentications. 


Overrideprotected void onActivityResult(final int requestdramrajani.com, final int resultdramrajani.com, final Intent data) super.onActivityResult(requestdramrajani.com, resultdramrajani.com, data); if (requestdramrajani.com == 101) // confirm that this response matches your request AccountKitLoginResult loginResult = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY); String toastMessage; if (loginResult.getError() != null) toastMessage = loginResult.getError().getErrorType().getMessage(); showErrorActivity(loginResult.getError()); else if (loginResult.wasCancelled()) toastMessage = "Login Cancelled"; else if (loginResult.getAccessToken() != null) toastMessage = "Success:" + loginResult.getAccessToken().getAccountId(); else toastMessage = String.format( "Success:%s...", loginResult.getAuthorizationdramrajani.com().substring(0, 10)); // If you have an authorization dramrajani.com, retrieve it from // loginResult.getAuthorizationdramrajani.com() // & pass it lớn your VPS và exchange it for an access token. // Success! Start your next activity... goToMyLoggedInActivity(); // Surface the result to your user in an appropriate way. Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show();

The Completed App

Now we can run our tiện ích lớn kiểm tra the SMS & email login flows!

*
*
*

Note that the Account Kit JavaScript SDK doesn"t tư vấn WebView login, so you can"t log people in from a WebView with Account Kit. You"ll have sầu to lớn write your Account Kit login interface with native sầu dramrajani.com.

Conclusion

In this quiông chồng tip tutorial, you learned about passwordless authentication using Facebook Account Kit: what it is, why you might want lớn consider using it, và how to implement it in your Android ứng dụng.

A word of warning, though: some see passwordless authentication as less secure. Most people wouldn"t use it when security is a priority, for example with a banking tiện ích. So use some discretion about when to lớn use it and when to lớn go with a more traditional authentication scheme.

To learn more about Facebook Account Kit, refer to the official documentation. And lớn learn more about Android development, kiểm tra out some of our other posts here on Envakhổng lồ Tuts+!