Chrome は、新しいパスワードを生成したり、保存されたパスワードの自動入力や同期をしたり、侵害されたパスワードについてユーザーに警告したりすることができます。つまり、ユーザーは自分でパスワードを管理する必要がなくなります。しかし、複数のドメインで同じアカウント管理バックエンドを利用している場合(たとえば、https://www.example.com と https://www.example.co.uk のような複数のトップレベル ドメイン)、Chrome はドメインをまたいで自動入力をしてくれません。その結果、異なるドメインに対して同じパスワードのエントリが 2 つできることになり、同期がとれなくなることもあります。
バージョン 91 以降の Chrome では、Digital Asset Links(DAL)で関連付けられたドメイン間で、保存したパスワードの自動入力が提案されます。DAL は、Android アプリとウェブサイトを関連付けるために、2015 年から利用されています。Chrome 91 では、サイト間で DAL を設定すると、Chrome がサイトをまたいでユーザーのログインをアシストしてくれます。DAL の関連付けをするには、両方のドメインの /.well-known/assetlinks.json に DAL 構文に従った JSON ファイルを配置する必要があります。
DAL の関連付けの詳しい設定方法については、すべての連携サイトで Chrome がログイン認証情報を共有できるようにするをご覧ください。
CredentialRequest request = new CredentialRequest.Builder() .setSupportsPasswordLogin(true) .setAccountTypes(IdentityProviders.GOOGLE) // you can add other identity providers, too .build(); Auth.CredentialsApi.request(mCredentialsApiClient, request).setResultCallback( new ResultCallback<CredentialRequestResult>() { public void onResult(CredentialRequestResult result) { if (result.getStatus().isSuccess()) { handleCredential(result.getCredential()) // sign in automatically!
HintRequest hintRequest = new HintRequest.Builder() .setEmailAddressIdentifierSupported(true) .setAccountTypes(IdentityProviders.GOOGLE) .build(); PendingIntent intent = Auth.CredentialsApi.getHintPickerIntent(mCredentialsApiClient, hintRequest); startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0); ... onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RC_HINT: if (resultCode == RESULT_OK) { Credential hint = data.getParcelableExtra(Credential.EXTRA_KEY); handleCredential(hint);
handleCredential(Credential credential) { if (!credential.getIdTokens().isEmpty()) { credential.getIdTokens().get(0).getIdToken(); // send the ID token string to your server } else { // otherwise, try fill the sign-in form fields and submit if password is available mEmailField.setText(credential.getId()); mPasswordField.setText(credential.getPassword());
GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory) .setIssuer("https://accounts.google.com") .setAudience(Arrays.asList(String.format("android://%s@%s", SHA512_HASH, PACKAGE_NAME))) .build(); ... GoogleIdToken idToken = verifier.verify(idTokenString); if (idToken == null) { Log.w(TAG, "ID Token Verification Failed, check the README for instructions."); return; } GoogleIdToken.Payload payload = idToken.getPayload(); Log.d(TAG, "IdToken:Email:" + payload.getEmail()); Log.d(TAG, "IdToken:EmailVerified:" + payload.getEmailVerified()); // based on the email address, determine whether you need to create account // or just sign user in
Credential credential = new Credential.Builder(hint) // if you signed in with ID token, // set account type to the URL for your app (instead of a password field) //.setAccountType("https://yourdomain.com") .setPassword(password) .build(); Auth.CredentialsApi.save(mCredentialsApiClient, credential).setResultCallback( new ResolvingResultCallbacks<Status>(this, RC_SAVE) {
getHintPicker
FusedLocationProviderApi
flushLocations
removeLocationUpdates
AppInvite.AppInviteApi.getInvitation()