发布于 2017-11-05 02:07:00
TL;博士,一键登录/自动登录库,包括凭证管理。您可能应该只使用库:https://developers.google.com/identity/one-tap/web/get-started
详细信息
JavaScript库支持使用Google帐户创建帐户(通过一个精简的内联用户界面,它可以显示在内容页面上,而用户必须导航到传统的基于按钮的用户界面,并确定选择哪个按钮/选项并与弹出/重定向交互)。
对于返回的用户,该库允许您在页面上以编程方式检索现有的一键/传统Google登录用户的令牌,以及支持它的浏览器中的凭据管理API中的密码。您可以使用如下代码来完成此操作:
const retrievePromise = googleyolo.retrieve({
supportedAuthMethods: [
"https://accounts.google.com",
"googleyolo://id-and-password"
],
supportedIdTokenProviders: [
{
uri: "https://accounts.google.com",
clientId: "YOUR_GOOGLE_CLIENT_ID"
}
]
});
retrievePromise.then((credential) => {
if (credential.password) {
// An ID (usually email address) and password credential was retrieved.
// Sign in to your backend using the password.
signInWithEmailAndPassword(credential.id, credential.password);
} else {
// A Google Account is retrieved. Since Google supports ID token responses,
// you can use the token to sign in instead of initiating the Google sign-in
// flow.
useGoogleIdTokenForAuth(credential.idToken);
}
}有关细节,请参阅文档。该库目前不支持非谷歌/密码形式的身份,您必须实现与其他提到的身份提供者SDK的登录流。
还要注意的是,任何与Google帐户(基于OAuth令牌或存储和同步密码)相关的登录都可以在Android和Chrome (以及其他基于令牌的帐户)中使用。
如有任何后续问题,请留下评论。
https://stackoverflow.com/questions/47096337
复制相似问题