如何实现“使用 google 登录”?在我的网站上?
在我的网站上,我想允许用户使用谷歌帐户登录。我打算使用 openid,但我想允许使用 google 登录,因为它有更多好处。我过去注意到一些网站能够使用 google (gmail) 帐户和 IIRC 登录,尽管它们不支持 openID(但我可能是错的)。
如何实现“使用 google 登录”?
On my site I would like to allow users to sign in with a google account. I plan to use openid but I would like to allow signing in with google because it has more benefits. I've noticed in the past a few sites that have the ability to sign in with a google (gmail) account and IIRC though they did NOT support openID (but I could be wrong).
How do I implement 'sign in with google'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您打算使用 OpenID,请使用它。 Google 已经是 OpenID 2.0 提供商。
Google 的 OpenID 提供商位于:https://www.google.com/accounts/o8/ud< /a>
(注意:在浏览器中访问该 URI 是没有意义的,但它确实适用于 OpenID。)
这主要在 Accounts API 页面,该页面还解决了 OAuth 以及混合和专有登录系统。根据您的网站,您可能还想使用 Friend Connect,它是一个 OpenSocial 容器,内部使用 OpenID 进行身份验证。我当然偏向 Google 朋友群,因为我是该项目的 DPE,但直接使用 OpenID 提供商可能会更好,除非您也做涉及社交图谱的事情。2012 年编辑: 您想要使用 OAuth 2.0 用于登录。 GFC 即将关闭 。
If you plan to use OpenID, use that. Google is already an OpenID 2.0 provider.
Google's OpenID provider is located at: https://www.google.com/accounts/o8/ud
(NOTE: There's no point visiting that URI in your browser, but it does work for OpenID.)
This is primarily addressed on the Accounts API page, which also addresses OAuth and the hybrid and proprietary login systems. Depending on your site, you may also want to use Friend Connect, which is an OpenSocial container that internally uses OpenID for authentication.I'm of course biased towards Friend Connect, since I'm the DPE for that project, but you're probably better served directly using the OpenID provider unless you're also doing stuff that involves a social graph.Edit for 2012: You want to use OAuth 2.0 for login. GFC is being shut down.
您可能对 RPX 感兴趣,这是一种一体化解决方案,可让人们选择他们想要的身份提供商用于登录您的网站。不仅支持 Google 和 OpenID,还支持许多其他内容。
RPX 负责与每个身份提供商交互的所有细节,并为您提供一个通用的 API 来使用。
You may be interested in RPX which is an all-in-one solution that lets people choose which identity provider they would like to use to log in to your site. Not only are Google and OpenID supported, but many others as well.
RPX takes care of all the details of interfacing with each identity provider, and gives you a common API to work with.
将 Google Sign-In 集成到您的网络应用中
创建一个 Google Developers Console 项目并客户端 ID。
加载 Google 平台库
您必须在集成 Google 登录的网页上包含 Google 平台库。
指定应用程序的客户端 ID
使用 google-signin-client_id 元元素指定您在 Google Developers Console 中为应用程序创建的客户端 ID。
注意:您还可以使用gapi.auth2.init()方法的client_id参数指定应用程序的客户端ID。
添加 Google 登录按钮 将
Google 登录按钮添加到网站的最简单方法是使用自动呈现的登录按钮。只需几行代码,您就可以添加一个按钮,该按钮会自动将自身配置为具有适合用户登录状态和您请求的范围的文本、徽标和颜色。
要创建使用默认设置的 Google 登录按钮,请将类为 g-signin2 的 div 元素添加到您的登录页面:
其他信息。可以在此处
其他 找到可能的解决方案是
使用 OAuth 2.0 访问 Google API< /a>
Auth 协议
OAuth 2.0 概述
OpenID Connect
用于服务器端 Web 应用的
OAuth 2.0 用于 JavaScript Web 应用的
OAuth 2.0 用于移动和应用的 OAuth 2.0桌面应用程序
Integrating Google Sign-In into your web app
Create a Google Developers Console project and client ID.
Load the Google Platform Library
You must include the Google Platform Library on your web pages that integrate Google Sign-In.
Specify your app's client ID
Specify the client ID you created for your app in the Google Developers Console with the google-signin-client_id meta element.
Note: You can also specify your app's client ID with the client_id parameter of the gapi.auth2.init() method.
Add a Google Sign-In button
The easiest way to add a Google Sign-In button to your site is to use an automatically rendered sign-in button. With only a few lines of code, you can add a button that automatically configures itself to have the appropriate text, logo, and colors for the sign-in state of the user and the scopes you request.
To create a Google Sign-In button that uses the default settings, add a div element with the class g-signin2 to your sign-in page:
Other Info. could be found here
Other Possible Solution is
Using OAuth 2.0 to Access Google APIs
Auth Protocols
OAuth 2.0 Overview
OpenID Connect
OAuth 2.0 for Server-side Web Apps
OAuth 2.0 for JavaScript Web Apps
OAuth 2.0 for Mobile & Desktop Apps
我相信您正在寻找的是 Google Accounts API。
I believe what you're looking for is the Google Accounts API.
我认为您想要的是 Google 朋友群编辑:不,您不需要不再是因为它已被弃用。
I think what you want is Google Friend Connectedit: No you don't any more as it has been deprecated.
在这种情况下,请添加以下代码
HTML
JS
In this case, add the following code
HTML
JS
Google SignIn 集成的简单步骤:
创建项目后,单击OAuth 同意屏幕并填写应用程序名称和应用程序等详细信息标识。可选详细信息,如域 URL、重定向 URL
转到凭据并单击“创建凭据”下拉列表和“创建凭据”。单击 Oauth 客户端 ID。在表格中填写详细信息
记下用于登录 API 集成的客户端 ID 和密钥
有关 API 集成,请查看 此。对于 react 和 Angular 应用程序,因此可以使用许多 NPM 包来轻松配置。
Google SignIn simple steps to integrate:
After creating a project click the OAuth consent screen and fill those details like the Application name and application logo. optional details like domain URL, redirect URL
Go to credentials and click create credentials dropdown & click Oauth client id. Fill the details in form
Note down the client Id and secret key for signIn API integration
For API integration, look at this. For react and angular applications so many NPM packages are avilable for easy configuration.
您可以查看 openId (http://openid.net/),这是 SO 使用的,并受谷歌。
You can look into openId (http://openid.net/) which is what SO uses, and is supported by Google.