我在我的应用中使用"Google登录".因此,我使用GoogleApiClient类来获取用户电子邮件和我后端所需的ID令牌.
当用户登录时,我可以访问一个Activity(当然),我使用该Activity让GoogleApiClient通过调用builder.enableAutoManage(myActivity,...)来处理UI生命周期内容.
这很好用.
但是,在稍后阶段(几天后),我需要获得一个新令牌(出于某种原因,我不会在这里进一步讨论).我想在没有用户交互的情况下静默获取此令牌.但是,在我需要这个新令牌的代码中,我无法访问任何Activity实例.这意味着我无法进行上述调用,即"builder.enableAutoManage".而且我发现,如果我不打那个电话,那么静默登录似乎不起作用.
我已附上以下代码.现在,看看"silentLogin"方法.只要我作为用户收到的令牌执行了实际登录,小于一小时,则语句"pendingResult.isDone"将返回true并且可以接收缓存的令牌.但是,如果我作为用户进行实际登录时收到的令牌超过一小时,那么就会调用"pendingResult.setResultCallback",但是"onResult"方法永远不会被调用,我无法获得新的令牌.如果我从一个活动做同样的事情(并且通过它也调用"builder.enableAutoManage"),就不会发生这个问题.
那么,有没有人知道我做错了什么,更重要的是 - 如何解决这个问题并获得一个新的令牌而无需访问活动实例?
我使用的是com.google.android.gms:play-services-auth:8.4.0
package com.google.samples.quickstart.signin;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.Scopes;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.OptionalPendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Scope;
/**
* Use this class to login with google account using the OpenId oauth method.
*/
public class GoogleLoginStackOverflow {
private static final String TAG = GoogleLoginIdToken.class.getName();
private static final String SERVER_CLIENT_ID = "XXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com";
private GoogleApiClient mGoogleApiClient;
private Context mContext;
private GoogleLoginStackOverflow(Context appContext) …Run Code Online (Sandbox Code Playgroud) android google-authentication google-signin googlesigninaccount
我试图找到相当于这个Android验证,但对于iOS.
最初发布在博客文章中, 但现在已合并到主要的Android文档中,验证让您知道3件事:然后,您知道:
关键是:
GoogleAuthUtil会发现Android应用和网络客户端ID位于同一个项目中,未经用户批准,会将ID令牌返回给Google签名的应用.
因此,我能够在不中断用户的情况下验证后端呼叫.
苹果公司是否有类似于iOS的东西,当苹果公司观察到iOS应用程序和网络客户端ID时,我可以获得Apple签署的ID令牌?
我发现了一个试图找到类似问题的SO问题,但我希望找到一个更简单的解决方案.这个问题已经超过一年了,所以我希望可能有更好的答案,可能还有新的CloudKit网络服务.
我尝试在Firebase连接的Android应用中实施Google登录.当我运行应用程序并按Google登录按钮时 - 没有任何反应.我在onActivityResult中收到此错误: Status {statusCode = DEVELOPER_ERROR,resolution = null}.
我的代码看起来像这样:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_GOOGLE_LOGIN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()){
GoogleSignInAccount account = result.getSignInAccount();
String emailAddres = account.getEmail();
getGoogleQAuthToken(emailAddres);
}
}
}
private void getGoogleQAuthToken(final String emailAddres){
AsyncTask<Void,Void,String> task = new AsyncTask<Void, Void, String>() {
String errorMessage = null;
@Override
protected String doInBackground(Void... params) {
String token = null;
try {
String scope = "oauth2:profile email";
token = GoogleAuthUtil.getToken(MainActivity.this, …Run Code Online (Sandbox Code Playgroud) android google-authentication firebase firebase-authentication firebaseui
我是 Flutter 的新手。我有Firebase Auth/Google Auth 的问题FirebaseUser未定义代码:
FirebaseAuth _auth = FirebaseAuth.instance;
GoogleSignIn googleSignIn = GoogleSignIn();
Future<FirebaseUser> currentUser() async { // The Issue is here in the Future<>
final GoogleSignInAccount account = await googleSignIn.signIn();
final GoogleSignInAuthentication authentication =
await account.authentication;
final GoogleAuthCredential credential = GoogleAuthProvider.getCredential(
idToken: authentication.idToken, accessToken: authentication.accessToken);
final AuthResult authResult = await _auth.signInWithCredential(credential);
final FirebaseUser user = authResult.user; // and here as I can't define this FirebaseUser object to return
return user;
}
Run Code Online (Sandbox Code Playgroud)
pubspec.yml
dependencies:
flutter:
sdk: …Run Code Online (Sandbox Code Playgroud) google-authentication dart firebase firebase-authentication flutter
我使用https://www.googleapis.com/auth/userinfo.email范围来获取经过身份验证的用户的电子邮件地址.但在进行身份验证时,Google会提示用户:
该应用程序想:
- 了解您在Google+上的身份(帮助图标显示:此应用请求获得与您的公开Google个人资料相关联的权限)
- 查看您的电子邮件地址
我不想要用户的Google+相关信息.我正在使用OAuth2身份验证方法.对于Authsub请求身份验证,它只需要电子邮件地址访问.如何单独访问用户的电子邮件地址?
scope google-authentication oauth-2.0 google-plus google-oauth
我有一个后台服务,调用GoogleAuthUtl.getTokenWithNotification它,它正常工作,但我正在尝试实现此功能的回调部分,但是无法正常工作.
我已经实现了一个广播接收器并将其添加到清单中,我的应用程序中也有一个活动.以下是相关的代码段.
GoogleAuthUtil.getTokenWithNotification
GoogleAuthUtil.getTokenWithNotification(this.getContext(), account, "oauth2:" + GmailScopes.GMAIL_SEND, null, new Intent(AuthReceiver.AUTH_INTENT));
Run Code Online (Sandbox Code Playgroud)
AuthReceiver
public class AuthReceiver extends BroadcastReceiver
{
public final static String AUTH_INTENT = "com.testoauth.AUTH_INTENT";
public AuthReceiver()
{
}
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("RECEIVER", "Received Auth broadcast.");
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest
<receiver android:name=".AuthReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.testoauth.AUTH_INTENT" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它没有收到广播.我没有在日志中看到任何异常,并且没有任何迹象表明接收器完全被调用,它在调试时甚至不会在断点处中断.我做错了什么吗?
编辑
我正在使用min sdk 16和目标sdk 25
从GoogleAuthUtil.getTokenWithNotification API文档中:
此方法专门用于后台任务.如果出现需要用户干预的错误,此方法负责推送相关通知.在用户解决通知之后,广播回叫.如果用户取消,则不会触发回调.
无论用户是否取消,都不会触发回调.除了ActivityManager显示通知(Displayed com.google.android.gms/.auth.uiflows.gettoken.GetTokenActivity)的说法之外,没有迹象表明com.testoauth.AUTH_INTENT已经在日志中发送了指定的广播意图(在这种情况下)."收到的Auth广播".日志中也没有消息.
包含此功能( …
android google-authentication google-play-services google-oauth android-broadcastreceiver
我正在通过JS使用谷歌登录,看来我的代码获取数据两次.我不确定为什么会这样.
当我点击"使用Google登录"按钮时,它会向用户吐出(console.log(result))数据.然后出现提示,要求我选择我的帐户(我登录了几个谷歌帐户).当我点击我想要的帐户时,代码会再次吐出该用户数据.
为什么会这样?这是一个问题,因为在我吐出数据的地方,我想做一个ajax调用来验证用户,然后重定向它们.所以从本质上说,它试图这样做两次 - 这并不酷,如果我不想使用凭据登录google在第一次转发时回传?
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
function googleLogin() {
var additionalParams = {
'callback': googleCallback
};
gapi.auth.signIn(additionalParams);
}
function googleCallback(authResult) {
if (authResult['status']['signed_in']) {
gapi.client.load('oauth2', 'v2', function() {
gapi.client.oauth2.userinfo.get().execute(function(resp) {
console.log(resp);
})
});
} else {
console.log('Sign-in state: ' + authResult['error']);
}
}
Run Code Online (Sandbox Code Playgroud)
更新:如果我退出所有Google帐户(除了一个且只有一个),谷歌的调用仍然是重复的.这次它登录,我看到console.log()两次输出数据.访问令牌是相同的.
更新2: console.log(resp)输出两次
更新3:更多说明:

javascript google-api google-authentication google-api-client google-oauth
在我的Android应用程序中,我试图在我的谷歌应用引擎后端服务器上验证谷歌令牌.但我总是得到这个例外:
com.google.android.gms.auth.GoogleAuthException: getToken(Unknown Source) exception
Run Code Online (Sandbox Code Playgroud)
我的代码:
private Account mAccount = AccountManager.get(this).getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE)[0];
private static final String SCOPE = "audience:server:client_id:" +Constants.WED_CLIENT_ID;
String token = GoogleAuthUtil.getToken(LoginActivity.this, mAccount.name, SCOPE);
Run Code Online (Sandbox Code Playgroud)
我已经尝试了Stackoverflow中提出的每个解决方案.
我是 python 新手,目前正在开发一个项目,该项目要求我将 pandas 数据帧从 google collab 导出到具有多个选项卡的 google 电子表格。以前,当我运行此特定代码时,没有错误,但现在它显示如下错误:
TypeError Traceback (most recent call last)
<ipython-input-74-c8b829c43616> in <module>()
5 gauth.credentials = GoogleCredentials.get_application_default()
6 drive = GoogleDrive(gauth)
----> 7 gc = gspread.authorize(GoogleCredentials.get_application_default())
2 frames
/usr/local/lib/python3.7/dist-packages/gspread/utils.py in convert_credentials(credentials)
59
60 raise TypeError(
---> 61 'Credentials need to be from either oauth2client or from google-auth.'
62 )
63
TypeError: Credentials need to be from either oauth2client or from google-auth.
Run Code Online (Sandbox Code Playgroud)
这是我用来创建身份验证的代码。
#Import PyDrive and associated libraries.
#This only needs to be done once …Run Code Online (Sandbox Code Playgroud) python google-authentication google-sheets pandas google-colaboratory
我创建了Google电子表格,并为所有人提供了编辑权限(即使没有登录也可以编辑).
这是链接.我想使用Google Spreadsheet API更新此表.但我收到了错误.我的要求是即使没有访问凭证也通过API更新工作表.
google-authentication google-sheets google-spreadsheet-api google-developers-console
android ×4
google-oauth ×3
firebase ×2
cloudkit ×1
dart ×1
firebaseui ×1
flutter ×1
google-api ×1
google-plus ×1
ios ×1
javascript ×1
oauth-2.0 ×1
pandas ×1
python ×1
scope ×1