[英]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:
在步骤中,您需要:
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.