-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GoogleAuth
can no longer be used with googleapis
: Type 'GoogleAuth<JSONClient>' is not assignable to type 'string | OAuth2Client | BaseExternalAccountClient | GoogleAuth<JSONClient> | undefined'
#1402
Comments
GoogleAuth
can no longer be used with google-auth-library
: Type 'GoogleAuth<JSONClient>' is not assignable to type 'string | OAuth2Client | BaseExternalAccountClient | GoogleAuth<JSONClient> | undefined'GoogleAuth
can no longer be used with googleapis
: Type 'GoogleAuth<JSONClient>' is not assignable to type 'string | OAuth2Client | BaseExternalAccountClient | GoogleAuth<JSONClient> | undefined'
Hey @sceee, I believe this was a temporary issue due to Closing as this cannot be reproduced. |
I'm also getting same issue? can you please guide me? |
@LearningLadoo this can usually be solved when all dependent libraries are up-to-date. |
Thank you, my google-auth-library was not updated. |
agreed, seems completely broken right now |
@MrBrax is Auth and it’s dependencies up-to-date? |
in the end it seemed that version 6 and 8 of auth was not compatible with the most recent youtube api package (6.0.0), but instead only 7.14.1 worked |
I had this issue a few months back using the latest versions of The first solution I found was to look at the version of The even easier solution was to drop |
yup i hovered over the error (something about oauth2client not being compatible) and it said 7.14.1 in the bundled version so that's what i chose to downgrade to |
@MrBrax All of our clients should be using auth V8 by now. What are the exact Google package(s) & versions are you using? |
i was using [email protected] and @googleapis/[email protected] which broke compatibility |
That's strange; |
I don't use node_modules but yarn 3 pnp, googleapis-common is at version 5.1.0 |
Looking a little closer, I see we have a publishing issue - I'll sync with the team and get this resolved for you. |
@MrBrax Hey! Circling back, we've fixed the publishing issue and |
Nice! |
|
@jatinsaini66 you can run |
hey @sceee i have problem with google-auth-library. Can you help? |
@chopyk89 looks like you are having a typo in |
@sceee when I create OAuth 2.0 Client IDs I was given JSON where all parameters are specified. This JSON has a field |
@sceee or I do, something is wrong)) |
@chopyk89 take a look at the docs here https://googleapis.dev/nodejs/google-auth-library/8.7.0/ . If you manually want to create an |
I'm running into the same issue with the Google Drive API. "@googleapis/drive": "5.1.0", Both are at their latest versions, but I'm getting this typescript error:
|
I'm not sure how this is possible as Could you double-check your installation? |
Hi @danielbankhead, I'm not sure what to tell you. I've deleted "dependencies": {
"@google-cloud/local-auth": "2.1.1",
"@googleapis/drive": "5.1.0",
"dotenv": "16.0.3",
"google-auth-library": "8.8.0"
},
"devDependencies": {
"@babel/core": "7.21.8",
"@babel/preset-env": "7.21.5",
"@babel/preset-typescript": "7.21.5",
"@types/express": "4.17.17",
"@types/jest": "29.5.1",
"@types/node": "18.16.3",
"babel-jest": "29.5.0",
"jest": "29.5.0",
"rimraf": "5.0.0",
"ts-node-dev": "2.0.0",
"typescript": "5.0.4"
} And this is the code I'm trying to run (most of which is taken directly from google's own docs at https://developers.google.com/drive/api/quickstart/nodejs but I'm just adding the typescript types): import { drive, drive_v3 } from '@googleapis/drive';
import { JSONClient } from 'google-auth-library/build/src/auth/googleauth';
import { OAuth2Client } from 'google-auth-library';
// excluded the other code, which is all from that quickstart guide
export async function authorize() {
let client: JSONClient | OAuth2Client | null = await loadSavedCredentialsIfExist(); // <-- the typing here seemed sketchy
if (client) {
return client;
}
client = await authenticate({
scopes: SCOPES,
keyfilePath: CREDENTIALS_PATH,
});
if (client!.credentials) {
await saveCredentials(client);
}
return client;
}
export async function listFilesAndFolders() {
// create a new Google Drive client
const client: OAuth2Client = await authorize(); // <-- this is where that type error is happening
try {
const rootFolderId = 'YOUR_ROOT_FOLDER_ID_HERE';
await listFolders(rootFolderId, client);
await listFiles(rootFolderId, client);
} catch (err) {
console.error('Error listing folders and files', err);
}
} |
@goodbomb this error is correct as your method, |
@danielbankhead Maybe I'm just ignorant to how TypeScript works, but how does one properly type that method based on the nodeJS example provided by Google? That If I remove the /**
* Reads previously authorized credentials from the save file.
*
* @return {Promise<OAuth2Client|null>}
*/
async function loadSavedCredentialsIfExist() {
try {
const content = await fs.readFile(TOKEN_PATH);
const credentials = JSON.parse(content);
return google.auth.fromJSON(credentials); // this is supposed to return an OAuth2Client
} catch (err) {
return null;
}
}
// This is the original untyped function taken directly from the Quick Start guide
async function authorize() {
let client = await loadSavedCredentialsIfExist();
if (client) {
return client;
}
client = await authenticate({
scopes: SCOPES,
keyfilePath: CREDENTIALS_PATH,
});
if (client.credentials) {
await saveCredentials(client);
}
return client;
} |
Is it as simple as casting the return? async function loadSavedCredentialsIfExist() {
try {
const content = await fs.readFile(TOKEN_PATH);
const credentials = JSON.parse(content.toString());
return auth.fromJSON(credentials) as OAuth2Client; // this gets rid of the error, but is that legit?
} catch (err) {
return null;
}
} |
@goodbomb in the JS sample we know given the context and usage,
Personally, I like const client = auth.fromJSON(credentials)
if ("refreshAccessToken" in client) {
return client; // this is definitely an `OAuth2Client`
} |
Thanks a lot @danielbankhead! Much appreciated! |
I came across a similar issue while working with Google's play integrity API If you are importing the required API using the individual module and If you set the auth for the parent Google import using the options method, you get However, for play integrity API at least, it had a provision to pass the auth to the generator function. Check if similar options params are available for API you are working with.
instead of
|
I have everything up to date and I still get the error
Here's my code import { GoogleAuth } from 'google-auth-library'
import { getGoogleCredentialsJSON } from "../../helpers/googleCredentials.js"
import { JSONClient } from 'google-auth-library/build/src/auth/googleauth.js'
export async function generateGoogleClient (): Promise<GoogleAuth<JSONClient>> {
const googleCredentialsJSON = await getGoogleCredentialsJSON()
const googleJSONClient = new GoogleAuth({
scopes: ['https://www.googleapis.com/auth/drive'],
credentials: googleCredentialsJSON
})
return googleJSONClient
} Here my package.json's dependencies
|
@ccmoralesj It sounds like you have multiple versions of auth. Consider running We may switch to a capabilities-based model for auth in the future (e.g. requiring an |
Apparently, I do have more versions but I didn't install them myself. Maybe the inner dependencies did it. What should I do here? |
I would recommend installing v8.9.0 for now ( |
i had the same issue with the newest youtube api too, the auth library seems to be very picky with the version, 8.9.0 works right now |
Opened up PR #1624 to greatly improve the experience when transitioning between different versions of |
My only google dependency (in package.json) is Type 'ExternalAccountAuthorizedUserClient' is not assignable to type 'string | BaseExternalAccountClient | GoogleAuth<JSONClient> | OAuth2Client | undefined'. Type 'ExternalAccountAuthorizedUserClient' is missing the following properties from type 'OAuth2Client': certificateCache, certificateExpiry, certificateCacheFormat, refreshTokenPromises, and 23 more. |
@danieltroger what’s your output of |
Thanks for the reply!
But I think it was something with my code, I did the following change and it fixed the type error Idk what I'm doing tho and if the code still works, but I'll see if it fails in the future (or maybe you know?) Small feedback: I checked here (because it's linked here) if there was any breaking change in how |
Yup. Works perfect! Thanks |
The former returned an
I will happily pass along this feedback - I think we can improve documentation for bundled packages as well. |
Spent way more time on this than I wanted to so have to share So trying to change to So I had to figure this out the hard way. A strategically placed import { google, Auth } from 'googleapis';
import { JSONClient } from 'google-auth-library/build/src/auth/googleauth';
import { Impersonated } from 'google-auth-library';
/**
* Reads previously authorized credentials from the save file.
*
*/
async function loadSavedCredentialsIfExist(){
try {
const content = await fs.readFile(TOKEN_PATH);
const credentials = JSON.parse(content.toString());
return google.auth.fromJSON(credentials) as Exclude<Impersonated, Auth.GoogleAuth<JSONClient>>;
} catch (err) {
return null;
}
} |
After digging through some of the code base, I landed on this snippet that is relatively straightforward and doesn't rely on TypeScript magic. import fs from "fs/promises";
import { Auth } from "googleapis";
async function loadSavedCredentialsIfExist() {
try {
const content = await fs.readFile(TOKEN_PATH, { encoding: "utf-8" });
const credentials = JSON.parse(content);
const refreshClient = new Auth.UserRefreshClient();
refreshClient.fromJSON(credentials);
return refreshClient;
} catch (err) {
return null;
}
} |
This seems to be an issue with
I get a version of this error on essentially every version going back to googleapis 133. The version numbers differ, but it seems like they are always out of sync. |
Seeing this error still with the current latest versions of 'google-auth-library' and '@google-analytics/admin'. "google-auth-library": "^9.15.0",
Type 'OAuth2Client' is missing the following properties from type 'GoogleAuth': #private, isGCE, jsonContent, cachedCredential, and 35 more.ts(2740) As an aside, going from oAuthClient -> GoogleAuth -> AnalyticsAdminServiceClient is incredibly verbose and I'm really hoping I find a more concise way to do this in the future. |
After updating
google-auth-library-nodejs
from v7.14.1 to v8.0.1, the following Typescript compile error occurs:Environment details
google-auth-library
version: v8.0.1Steps to reproduce
tsc
for Typescript compileThe text was updated successfully, but these errors were encountered: