smart lock for password @ game devfest bangkok 2015
TRANSCRIPT
Smart Lock for PasswordsSomkiat Khitwongwattana
Android Developer@Nextzy & Android GDE & Contributor@Droidsans
Smart Lock for Passwords
Smart Lock• Signed-in across devices• For Android and Chrome• Reduce the risk of forgotten
Smart Lock for Passwords
Credentials API• Retrieve and save app login credentials• Auth.CREDENTIALS_API• Multiple user credentials supported
Smart Lock for Passwords
Credential Management Capability• Username• Name• Password• Profile Picture URL• Account Type
Smart Lock for Passwords
Smart Lock Flow
• Auto sign-in• Multiple credentials• No credentials / Signed out
• App start • Signed in
Smart Lock for Passwords
Get Started• Add Google Play Services dependency
compile 'com.google.android.gms:play-‐services:7.8.0'
• Declare the version of Google Play services<application> ... <meta-‐data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> ... </application>
Smart Lock for Passwords
Get Started• Create an OAuth 2.0 client ID
• Open Google Developer Console• Create project
Smart Lock for Passwords
Get Started
• Example client ID
478989446966-gdahdsjn77selo6f1rnab6e2pd1nq4f3.apps.googleusercontent.com
Smart Lock for Passwords
Let's Get CodingGoogleApiClient mCredentialsApiClient; ... mCredentialsApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .enableAutoManage(this, 0, this) .addApi(Auth.CREDENTIALS_API) .build();
Smart Lock for Passwords
Store CredentialsCredential credential = new Credential.Builder(username) .setPassword(password) .setAccountType(accountType) .setName(name) .setProfilePictureUri(url) .build();
Smart Lock for Passwords
Store CredentialsAuth.CredentialsApi.save(mCredentialsApiClient, credential) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { ... } });
Smart Lock for Passwords
Store Credentialsint REQUEST_CODE_SAVE = 123;
Status status = result.getStatus(); if(status.isSuccess()) { ... } else { if(status.hasResolution()) { status.startResolutionForResult(this, REQUEST_CODE_SAVE); } else { ... } }
Smart Lock for Passwords
Store Credentials@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { ... if (requestCode == REQUEST_CODE_SAVE) { if (resultCode == RESULT_OK) { ... } else { ... } } ... }
Smart Lock for Passwords
Request Credentials
CredentialRequest request = new CredentialRequest.Builder() .setSupportsPasswordLogin(true) .build();
Smart Lock for Passwords
Request CredentialsAuth.CredentialsApi.request(mCredentialsApiClient, request) .setResultCallback(new ResultCallback<CredentialRequestResult>() { @Override public void onResult(CredentialRequestResult credentialRequestResult) { ... } });
Smart Lock for Passwords
Share Credentials with Apps and Sites• Verify website's sign-in domain by using the Google Search Console
• Make an association to Play Developer Console
• Must be available through HTTPS
Smart Lock for Passwords
Reference
https://developers.google.com/identity/smartlock-passwords
https://www.youtube.com/watch?v=M3Udfu6qidk
Smart Lock for Passwords Documentation
Google Play Services 7.5 (100 Days of Google Dev)