google-auth-library-nodejs | 🔑 Google Auth Library for Node.js | OAuth library
kandi X-RAY | google-auth-library-nodejs Summary
kandi X-RAY | google-auth-library-nodejs Summary
This is Google's officially supported node.js client library for using OAuth 2.0 authorization and authentication with Google APIs. A comprehensive list of changes in each version may be found in the CHANGELOG. Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of google-auth-library-nodejs
google-auth-library-nodejs Key Features
google-auth-library-nodejs Examples and Code Snippets
import * as admin from "firebase-admin"; // OR IMPORT IT FROM SOME SINGLETON initializeFirebaseAdmin FUNCTION
import { NextApiHandler } from "next";
import SERVICE_ACCOUNT from "some-path/serviceAccount.json";
interface CredentialBody {
$ npm install @grpc/grpc-js
$ npm install google-auth-library
$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account-key.json
const grpc = require('@grpc/grpc-js');
const { GoogleAuth } = require('google-
$ npm uninstall --save google-auth-library
$ npm install --save googleapis@39
'use strict';
const {google} = require('googleapis');
const sampleClient = require('../sampleclient');
const fs = require('fs');
const
npm install google-auth-library@0.* --save
npm install google-auth-library -- save
....
"dependencies": {
"google-auth-library": "^1.3.1",
"googleapis": "^26.0.1"
}
npm install google-auth-library@0.* --save
npm install google-auth-library -- save
....
"dependencies": {
"google-auth-library": "^1.3.1",
"googleapis": "^26.0.1"
}
Community Discussions
Trending Discussions on google-auth-library-nodejs
QUESTION
Getting this error in Next.js _middleware
file when I try to initialize Firebase admin V9. Anyone know how to solve this issue?
ANSWER
Answered 2022-Feb-14 at 08:43The Edge Runtime, which is used by Next.js Middleware, does not support Node.js native APIs.
From the Edge Runtime documentation:
The Edge Runtime has some restrictions including:
- Native Node.js APIs are not supported. For example, you can't read or write to the filesystem
- Node Modules can be used, as long as they implement ES Modules and do not use any native Node.js APIs
You can't use Node.js libraries that use fs
in Next.js Middleware. Try using a client-side library instead.
QUESTION
I'm following Google's RTDNs guide on enabling Real-Time Developer Notifications. I've successfully created the topic and subscription and have received the push notifications sent to the API that I have created. I would now like to authenticate and validate these messages. For that, I'm following this guide on Authentication and Authorization. Their developer documentation here and here has a seemingly useful example.
The IssueAfter following the resources outlined above, I get the following error:
...ANSWER
Answered 2021-Feb-23 at 17:58Turns out the kid
was invalid and therefore threw the No pem found for envelope
error. Once a valid kid
was supplied, the error no longer persisted.
QUESTION
I'm trying to authenticate an API call made to my server (on Cloud Run) from a Cloud Scheduler cron job.
I'm trying to use a service account to this.
Note: this is all happening inside the same Project.
References:
This is what I'm doing:
STEP 1 - Create the service account
I went to https://console.cloud.google.com/apis/credentials and created a new service account. I've assigned the role as owner
.
STEP 2 - Create the cron job.
I went to https://console.cloud.google.com/cloudscheduler to create the cron job like I always do.
In the service account
field I've put my service account e-mail. In the Audience
field, I've put my project id because at some point I got an error saying that it was expecting it to be the name of my project id.
This was the error:
Firebase ID token has incorrect "aud" (audience) claim. Expected
"PROJECT_ID"
STEP 3 - Running the job and identify decoding the token:
This is the code on my server:
...ANSWER
Answered 2021-Jan-28 at 15:25After a morning in hell trying to debug this, here is what I've found.
It seems that firebase-admin
's admin.auth().verifyIdToken()
only works for tokens generated from the firebase
SDK.
I got it to work by using the google-auth-library
directly.
I did the following.
NOTE: The rest of the code is the same (using the same service account as described in the question):
QUESTION
I'm generating a JWT using google-auth-library-nodejs
by providing the credentials through env variables, similar to the sample code from here.
ANSWER
Answered 2020-Oct-13 at 13:28client_x509_cert_url
provided in the question above was not the right x-google-jwks_uri
. It actually has to be https://www.googleapis.com/oauth2/v1/certs
.
After changing the URI, the kid
s match.
If anyone has a clue why that is, it would be much appreciated.
QUESTION
I have a React + GraphQL application that reaches out to a Google Cloud Function to run some code. Currently I am allowing unauthenticated access, but I wish to lock it down. I am not seeing how I can authenticate like this in my React application:
...ANSWER
Answered 2020-Oct-08 at 08:38It is not advised to use service account authentication from a web app. But if you would need to run this app locally for testing purposes, I would say you could use google-auth-library
. More info and code examples can be found here.
You would also need the "Cloud Functions Invoker" role for the service account you are using.
Having said this, I would advise you to offload your authentication to a dedicated authentication provider like Firebase authentication, Auth0, or Okta.
QUESTION
I am trying to follow https://developers.google.com/sheets/api/quickstart/nodejs tutorial I am using typescript and I like the type annotation and auto-complition features it provides and I would like to re-write the example in typescript and async rather than callbacks. Sadly I am stuck, OAuth2Client. in my code I creating an oauth client inside a function like this:
...ANSWER
Answered 2020-Aug-20 at 16:18As of Jun 19 a merge request adding this feature has been approved. https://github.com/googleapis/google-api-nodejs-client/issues/2208
QUESTION
What i want to do: To call a google function from my server/machine & limit it usage with a (simple) authentication.
What i use: Node.js, google-auth-library library for authentication.
What have I done/tried:
1) Created a project in Google Cloud Functions
2) Created a simple google function
...ANSWER
Answered 2020-May-10 at 19:34When you call a private function (or a private Cloud Run) you have to use a google signed identity token.
In your code, you use an access token
QUESTION
I am trying to consume google youtube data apis which has support for api key type of credentials.
https://developers.google.com/youtube/registering_an_application
I am trying to use google auth library for node js to communicate with the apis
https://github.com/googleapis/google-auth-library-nodejs
There is an example of this API with oAuth credentials and service account credentials.
I know that api key is supposed to be used by client side applications like browser based javascripts. So i see example with browser based google apis.
But is there any example where api keys can be used with google node js client library ?
Best Regards,
Saurav
...ANSWER
Answered 2020-Mar-19 at 22:24You can use Google API NodeJS client using an API key on NodeJS. Just put the API key instead of the oauth client in the auth
field :
QUESTION
Click here to see Overview Diagram
Hi All,
I have service A that needs to call service B in different network domain. To make a call to service B, service A gets access token from identity provider then call service B with the access token in Http Authorization header. When there are multiple or concurrent requests to service A, I want to minimize the calls to identity provider to get access token. So I plan to implement caching by using https://www.npmjs.com/package/lru-cache which is similar to the approach using by google-auth-library
https://github.com/googleapis/google-auth-library-nodejs/blob/master/src/auth/jwtaccess.ts.
The service A will call identity provider to get access token and store to the cache. When the next request come in, the service A will use the token from cache and calls service B. If the cache item is expired, then service A will get service token and store in cache.
I have the following questions:
- How do we handle race condition when there are concurrent request to service A that can cause multiple requests are sent to get access token and have multiple updates to the cache?
- Let say, access token have 1 hour expiry. How do we have mechanism to get a new token before the token is expired?
Any comments would be very appreciated. Thank you in advance.
...ANSWER
Answered 2020-Mar-18 at 04:34It sounds like you would benefit from a little singleton object that manages the token for you. You can create an interface for getting the token that does the following:
- If no relevant token in the cache, go get a new one and return a promise that will resolve with the token. Store that promise in the cache in place of the token.
- If there is a relevant token in the cache, check it's expiration. If it has expired or is about to expire, delete it and go to step 1. If it's still good, return a promise that resolves with the cached token (this way it always returns a promise, whether cached or not).
- If the cache is in the process of getting a new token, there will be a fresh token stored in the cache that represents the future arrival of the new token so the cache can just return that promise and it will resolve to the token that is in the process of being fetched.
The caller's code would look like this:
QUESTION
I've been trying to connect to Admob API from an AWS Lambda to extract some values from reports automatically from time to time. I've successfully got google-auth-library-nodejs to a layer and I am trying to use it to connect to Admob API.
I've made sure to give my Service account an Owner role and I've added the necessary GOOGLE_APPLICATION_CREDENTIALS path to the environement variables.
This is the code that I've added to my Lambda:
...ANSWER
Answered 2020-Feb-26 at 20:52The problem is you are trying to use a service account where OAuth User Credentials are required. You will need to implement the OAuth 2 Flow where the user enters their Google username and password.
AdMob: Authorization for the request
Refer to the following Google example on how to create a node.js OAuth 2 client.
https://github.com/googleapis/google-auth-library-nodejs#oauth2
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install google-auth-library-nodejs
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page