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 " />
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.
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.
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.
To begin lớn use Account Kit, you"ll need:
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.
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.+"
YourAPPIdYourAccountKitClientTokenAlso include the Account Kit theme in your styles.xml.
public class MyApplication extends Application
Override public void onCreate() super.onCreate(); AccountKit.initialize(getApplicationContext());
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);
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();
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.
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+!