简体   繁体   English

如何使用Firebase IdToken生成OAuth Access for Google drive?

[英]How to use Firebase IdToken to generate OAuth Access for Google drive?

Update更新

In my Nativescript-Angular application I'm using @nativescript/firebase plugin which uses Firebase authentication and in the scope I have provided https://www.googleapis.com/auth/drive .在我的 Nativescript-Angular 应用程序中,我使用@nativescript/firebase插件,它使用 Firebase 身份验证,在 scope 中,我提供了https://www.googleapis.com/auth/drive

firebase
        .login({
          type: firebase.LoginType.GOOGLE,
          googleOptions: {
            scopes: ["email", "https://www.googleapis.com/auth/drive"],
          },
        })
        .then((user: firebase.User) => {
          //Firebase ID Token
          const idToken = value.providers[0].token;
        })
        .catch((err) => {
          console.log(err);
        });

While running application, it asked for user login along with user's consent for Google drive access .在运行应用程序时,它要求用户登录以及用户同意访问 Google 驱动器 After successful authentication it returns a Firebase Id Token.身份验证成功后,它会返回一个 Firebase Id 令牌。

In the next step application requires to access user's Google Drive.在下一步中,应用程序需要访问用户的 Google Drive。 As I know Google Drive API requires OAuth Access token while application has Firebase Token.据我所知,Google Drive API 需要 OAuth 访问令牌,而应用程序具有 Firebase 令牌。

https://www.googleapis.com/drive/v3/files

My questions is: How to generate OAuth Access token which is capable to access user's Google drive?我的问题是:如何生成能够访问用户的 Google 驱动器的 OAuth 访问令牌? OR Is there any alternate solution for this?或者是否有任何替代解决方案?

From what I can determine, the FirebaseNativeScript library's getAuthToken() call returns an ID token.据我getAuthToken() ,FirebaseNativeScript 库的getAuthToken()调用返回一个 ID 令牌。

Firebase Authentication users do not necessarily have access to Google Drive. Firebase 身份验证用户不一定有权访问 Google Drive。 Instead you'll need to use the user's OAuth2 token (the same one that is used to sign in to Firebase) to access Google Drive.相反,您需要使用用户的 OAuth2 令牌(与用于登录 Firebase 的令牌相同)来访问 Google Drive。 In steps, you'll need to:在步骤中,您需要:

  1. request the additional OAuth scopes needed to access Drive,请求访问 Drive 所需的其他 OAuth 范围,
  2. capture the OAuth token (not a Firebase token) and,捕获 OAuth 令牌(不是 Firebase 令牌)并且,
  3. use that to access Drive.使用来访问云端硬盘。

If you've tried this already, please edit your question to show what you've tried.如果您已经尝试过,请编辑您的问题以显示您尝试过的内容。

It has been resolved.已经解决了。 Basically the problem is with @nativescript/firebase plugin which is not returning accessToken.基本上问题出在不返回 accessToken 的@nativescript/firebase插件上。 I have customised the plugin which is now returning accessToken that I am able to authorise on Google APIs.我已经自定义了插件,该插件现在返回我能够在 Google API 上授权的 accessToken。

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

相关问题 如何获取 Firebase 实时数据库 AuthToken - How to get the Firebase Realtime Database AuthToken 如何获取访问令牌以使用Firebase在Google API中注册iOS设备 - How to get the access token to register iOS device in Google API with Firebase 如何从 firebase persistedinstallation.json 中清除 authtoken - How to clear the authtoken from firebase persistedinstallation.json 如何在处理请求的 rest 之前验证 Firebase AuthToken - How to validate Firebase AuthToken before handling the rest of the request 如何使Google端点API使用Firebase身份验证? - How can I make google endpoints API to use Firebase authentication? 如何使用 API 存储在 Google 中的密钥 Firebase 云函数 - How to use API Keys stored in Google Firebase Cloud Functions 如何使用Postman通过Firebase身份验证测试Google App Engine API? - How to use Postman to test a Google App Engine API with Firebase authentication? 如何将Firebase存储图像与Google Cloud Vision API一起使用? - How to use Firebase Storage image with Google Cloud Vision API? 如何在不依赖 Google Play 服务的情况下在 Android 上使用 Firebase API? - How to use Firebase API on Android without the Google Play Service dependency? 如何通过Google Apps脚本使用Firebase Auth REST API? - How to use Firebase Auth REST API using Google Apps Script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM