我刚刚在我们的主页上实现了 Google JavaScript 登录按钮,一切都按照预期的方式工作,但这有时很糟糕..
所以问题是我们的用户在同一台计算机上使用我们的应用程序,每天有 3-4 个不同的用户。通过谷歌登录,我们可以在我们自己的网站中实现一些谷歌产品功能。
我了解使用 google 登录会使您登录 Google 帐户,并授予申请权限。我也明白这是让用户的生活更轻松的方式,而不是每次都在每个网站上登录。
我可以通过GoogleAuth.signOut()或轻松删除应用程序权限GoogleUser.disconnect(),即使使用GoogleAuth.disconnect(),因此.isSignedIn()将变为假,因此用户将始终拥有提示屏幕,我也使用prompt: 'select_account'on.signIn()确保即使是单个用户也会获得提示屏幕。
问题是当第二个用户进入我们的登录屏幕并选择“使用 Google 登录”时,他实际上可以在提示屏幕中选择任何以前的用户并以不是他自己的身份进入我们的应用程序,但实际上可以选择以前的用户并进行身份验证自己作为对方无需输入任何密码。仅当以前的用户也从其 Goole 帐户注销时,才会询问密码。
我知道一个 hack 是将用户重定向到 URL:
https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=YOUR_REDIRECT_URL
但这似乎是一个非常糟糕的解决方案,因为我们的用户也将我们的应用程序与他们的个人设备一起使用,所以如果他们从他们登录的所有应用程序中注销,那就有点糟糕了。
我知道在每次登录时询问密码并不是 auth2 打算工作的方式,但我确定有一种方法可以强制用户在每次按下“用谷歌登录”按钮时输入密码。
我花了好几个小时寻找解决方案并尝试了多种方法,我希望你们中有人能指出我错过的大海捞针
javascript google-api-js-client google-signin googlesigninapi
这是我得到的错误
400. That’s an error.
Error: invalid_request
Invalid parameter value for approval_prompt: 'auto'' is not valid
Run Code Online (Sandbox Code Playgroud)
请求详细信息
response_type=code
access_type=offline
client_id=xyz-
xyx.apps.googleusercontent.com
redirect_uri=http://localhost/xyz/init/googleCallBack.php
state=scope=https://www.googleapis.com/auth/plus.me
approval_prompt=auto'
Run Code Online (Sandbox Code Playgroud)
这是谷歌登录的配置
$gClient= new Google_Client();
$gClient->setAuthConfig('init/client_secret.json');
$gClient->setApprovalPrompt('consent');
$gClient->setApplicationName('abc');
$gClient->setAccessType('offline');
$gClient>setRedirectUri('http://localhost/xyz/init/googleCallBack.php';
$gClient->setScopes(Google_Service_Plus::PLUS_ME);
Run Code Online (Sandbox Code Playgroud)
我尝试设置了 Approval_prompt 或同时提示两者,但如果我不设置这两个,则它不起作用,我仍然得到无效参数“prompt=auto”
如何退出 Google Sign In?
我知道我可以调用mGoogleSignInClient.signOut(),但我在登录活动中创建了 mGoogleSignInClient。我如何在我的设置活动中访问它(注销发生的地方)?
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("id_token")
.requestEmail()
.build()
googleSignInClient = GoogleSignIn.getClient(this, gso)
Run Code Online (Sandbox Code Playgroud)
在我的设置活动中,我有注销按钮,我希望能够调用一些与 Google Sign-In SDK 和注销相关的静态方法。
我真的需要将上述步骤(我在登录活动中实现的)重复到我的设置活动(注销按钮所在的位置)中吗?
android android-activity kotlin google-signin googlesigninapi
我试图将谷歌登录集成到我的应用程序中.当我点击按钮时,应用程序关闭(不会崩溃).我在这里犯的错是什么?我尽力遵循谷歌开发者网站告诉我的内容.我提前为长代码道歉.
我的Java代码:
import static com.google.android.gms.common.SignInButton.COLOR_DARK;
public class User_Name extends AppCompatActivity implements
GoogleApiClient.OnConnectionFailedListener{
private PrefManager2 prefManager;
SignInButton signInButton;
String email, name;
LoginButton loginButton;
GoogleApiClient mGoogleApiClient;
private static final int RC_SIGN_IN = 9001;
SQLiteDatabase db;
private GoogleSignInOptions googleSignInOptions;
private static final String EMAIL_PATTERN = "^[a-zA-Z0-9#_~!$&'()*+,;=:.\"(),:;<>@\\[\\]\\\\]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*$";
private Pattern pattern = Pattern.compile(EMAIL_PATTERN);
private Matcher matcher; //validate email
Button normalLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefManager = new PrefManager2(this);
if (!prefManager.isFirstTimeLaunch()) {
launchHomeScreen(); //custom method
finish();
}
setContentView(R.layout.activity_user__name);
googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestId().build();
mGoogleApiClient …Run Code Online (Sandbox Code Playgroud) 最初,我在检查是否已将数据保存到钥匙串中时遇到了问题。我找到了这篇文章并遵循了 BhavinBhadani 的建议:
每当您检查 if ([GIDSignIn sharedInstance].hasAuthInKeychain) 时,在此之前添加您的登录范围..
https://github.com/googlesamples/google-services/issues/27
这解决了我GIDSignIn.sharedInstance().hasAuthInKeychain()在用户之前成功登录然后杀死应用程序并重新运行后返回 true 的第一个问题。
但是现在我正在做以下事情:
let signIn = GIDSignIn.sharedInstance()
signIn.scopes = [Constants.GOOGLE_CLIENT_SCOPE, Constants.GOOGLE_OIDC_SCOPE]
if GIDSignIn.sharedInstance().hasAuthInKeychain() {
print("We have saved in keychain")
if let u = GIDSignIn.sharedInstance().currentUser {
getData(dataApi)
}
else {
// THIS CODE IS BEING SUCCESSFULLY HIT
GIDSignIn.sharedInstance().signInSilently()
getApplicationData(dataApi)
}
}
Run Code Online (Sandbox Code Playgroud)
然而,即使在做GIDSignIn.sharedInstance().signInSilently()了之后:GIDSignIn.sharedInstance().currentUser是零。
有没有人成功用于signInSilently()再次填充 currentUser 数据?
我执行本教程中取出过程中谷歌标志https://developers.google.com/identity/sign-in/ios/sign-in?configured=true&ver=swift
正如我在那里看到的那样,作者写道:
在这些示例中,视图控制器是UIViewController的子类.如果在你的项目,实现GIDSignInUIDelegate该类不是的UIViewController的子类,实现signInWillDispatch:错误:,签到:presentViewController:和签到:dismissViewController:在GIDSignInUIDelegate协议的方法.
所以按照他的建议我写了如下:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Initialize sign-in
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
GIDSignIn.sharedInstance().delegate = self
return true
}
// [START openurl]
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
}
// [END openurl]
@available(iOS 9.0, *)
func application(app: UIApplication, openURL url: NSURL, …Run Code Online (Sandbox Code Playgroud) <html>
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="MY_CLIENT_ID_ON_GOOGLE_DEV.apps.googleusercontent.com">
<!-- To integrate Google Sign-in -->
<script src="https://apis.google.com/js/api.js"></script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
不显示。这个HTML片段有什么问题?我还需要做其他事情才能显示Google登录按钮吗?
我的 Google 登录有问题。我按照服务器端应用程序的Google 登录中的步骤操作 完成所有这一步之后,我有这个在服务器上运行的 html 文件:
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/Article">
<head>
<link rel="stylesheet" href="theme.css">
<!-- BEGIN Pre-requisites -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer></script>
<!-- END Pre-requisites -->
<script>
function start() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'CLIENT_ID'
});
});
}
</script>
</head>
<body>
<button id="googleBtn">Connect</button>
<script>
$('#googleBtn').click(function() {
auth2.grantOfflineAccess().then(googleCallback);
});
</script>
<script>
function googleCallback(authResult) {
if (authResult['code']) {
console.log(authResult);
} else {
console.log(authResult);
}
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
第一部分工作完美(我认为),当我单击按钮时,会弹出一个窗口,我选择一个帐户并获得一个代码。所以现在,我想获取电子邮件和个人资料,因此我在 nodejs 中发出此请求以使用访问令牌交换代码。
var form …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Google登录示例,但是它不起作用。我收到ApiException statusCode = 10
我使用与此处相同的代码 https://developers.google.com/identity/sign-in/android/
android google-play-services google-signin googlesigninaccount googlesigninapi
android ×3
ios ×2
swift ×2
google-api ×1
html ×1
javascript ×1
kotlin ×1
node.js ×1
oauth ×1
php ×1