简体   繁体   English

当我从 Flutter 应用程序中的开发人员控制台获得有效的客户端 ID 时,如何使用 Google 登录 Package 获取有效的服务器身份验证令牌?

[英]How to get valid Server Auth Token using Google Sign In Package when I have a valid client ID from developers console in Flutter app?

I am trying to get the server auth token which needs to be sent to the backend so that they can pull the data from Google Fit API but they need this token after a user allows some scopes from the Android app.我正在尝试获取需要发送到后端的服务器身份验证令牌,以便他们可以从 Google Fit API 中提取数据,但是在用户允许 Android 应用程序的某些范围后,他们需要此令牌。 My firebase and google cloud project is one for which I am using google-services.json file.我的 firebase 和谷歌云项目是我使用google-services.json文件的项目之一。 I have generated Client ID from Google API Console which is also present in google-services.json .我从 Google API 控制台生成了客户端 ID,该控制台也存在于google-services.json中。 After doing all of that I am still getting server auth token as null.在完成所有这些之后,我仍然将服务器身份验证令牌作为 null。 How can I get the correct server auth code?如何获得正确的服务器验证码?

void connectWithGoogleFit() async {
    final GoogleSignIn googleSignIn = GoogleSignIn(
        clientId:
            '116565654179-8764764.apps.googleusercontent.com',
        scopes: <String>[
          'email',
          'https://www.googleapis.com/auth/fitness.activity.read',
        ]);
    final GoogleSignInAccount googleUser = await googleSignIn.signIn();
    final GoogleSignInAuthentication googleSignInAuthentication =
        await googleUser.authentication;
    String serverAuthToken = googleSignInAuthentication.serverAuthCode;
    print('token');
    print(serverAuthToken);
  }

I am trying to get the server auth token which needs to be sent to the backend so that they can pull the data from Google Fit API but they need this token after a user allows some scopes from the Android app.我正在尝试获取需要发送到后端的服务器身份验证令牌,以便他们可以从 Google Fit API 中提取数据,但是在用户允许 Android 应用程序的某些范围后,他们需要此令牌。 My firebase and google cloud project is one for which I am using google-services.json file.我的 firebase 和谷歌云项目是我使用google-services.json文件的项目之一。 I have generated Client ID from Google API Console which is also present in google-services.json .我从 Google API 控制台生成了客户端 ID,该控制台也存在于google-services.json中。 After doing all of that I am still getting server auth token as null.在完成所有这些之后,我仍然将服务器身份验证令牌作为 null。 How can I get the correct server auth code?如何获得正确的服务器验证码?

void connectWithGoogleFit() async {
    final GoogleSignIn googleSignIn = GoogleSignIn(
        clientId:
            '116565654179-8764764.apps.googleusercontent.com',
        scopes: <String>[
          'email',
          'https://www.googleapis.com/auth/fitness.activity.read',
        ]);
    final GoogleSignInAccount googleUser = await googleSignIn.signIn();
    final GoogleSignInAuthentication googleSignInAuthentication =
        await googleUser.authentication;
    String serverAuthToken = googleSignInAuthentication.serverAuthCode;
    print('token');
    print(serverAuthToken);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有人设法从谷歌登录 (Flutter) 获取 id 令牌 - Did anyone manage to get the id token from google sign in (Flutter) 如何在 Flutter 应用程序中从 Azure 获取有效的 RS256 令牌? - How to get a valid RS256 token from Azure in a Flutter app? 颤振:PlatformException(sign_in_failed,org.openid.appauth.oauth_token,invalid_audience:受众不是有效的客户 ID。,null) - flutter: PlatformException(sign_in_failed, org.openid.appauth.oauth_token, invalid_audience: Audience is not a valid client ID., null) Firebase Auth:如何使用id token登录? - Firebase Auth: How to sign in using id token? 如何从Flutter退出Google Auth表单? - How do I sign out form Google Auth from Flutter? 如何通过谷歌登录获取访问令牌 -- Flutter - How can i get the access token through google sign in -- Flutter 如何从 Flutter 上的 Firebase Auth 获取用户 ID 令牌更改 - How to get user ID token changes from Firebase Auth on Flutter 如何在 flutter 中获取谷歌登录访问令牌 - How to get google sign in access token in flutter 在flutter中使用graphql注册时如何获取令牌 - how to get token when sign up using graphql in flutter 使用 firebase 身份验证的 Flutter 应用程序中的 Google sign_in_failed 错误 - Google sign_in_failed error in a Flutter app using firebase auth
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM