Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
google-service-account
Advanced tools
Readme
Make authenticated requests using a Google service account.
This maintains an active Google service account token, allowing you to make server-to-server requests. It will automatically re-fetch a new token if a previous one expires.
To make a valid connection, you just attach an Authorization
property to your outgoing request's headers
object. This module returns that object.
$ npm install --save google-service-account
error handling omitted
var request = require("request")
var authorize = require("google-service-account")({
keyFile: "path/to/keyfile.json"
})
authorize(function (err, headers) {
request({
method: "GET",
uri: "https://www.googleapis.com/pubsub/v1beta1/subscriptions",
headers: headers
}, function () {
// Request callback.
})
})
Each time you invoke authorize()
, a new token may be fetched if necessary. Be sure to call it each time you make an outgoing request.
If the example above looked a little verbose for you, you may also use the authorize
function for its extending functionality:
authorize({
method: "GET",
uri: "https://www.googleapis.com/pubsub/v1beta1/subscriptions"
}, function (err, requestObject) {
request(requestObject, function () {
// Request callback.
})
})
If even that gets tiresome, you can always write up a quick helper for your app:
function makeAuthorizedRequest(opts, cb) {
authorize(opts, function (err, requestObject) {
request(requestObject, cb)
})
}
// ...later...
makeAuthorizedRequest({
method: "GET",
uri: "https://www.googleapis.com/pubsub/v1beta1/subscriptions"
}, function(err, response) {
// Request callback.
})
One of the following is required:
Object
The contents of a JSON key file downloaded from the Google Developers Console.
String
Path to a JSON key file downloaded from the Google Developers Console.
Array
The scopes your request requires.
Function
Invoke this method every time you need a valid token. It will handle requesting a new token if necessary, and will return it to your callback as part of an HTTP request headers object:
{
headers: {
Authorization: "..token.."
}
}
Object
The object you pass in here will be extended with the token object in the format above.
Function
The callback function receives a HTTP request headers
object, containing a valid token.
Invoke this method to get the credentials object, containing the client_email, client_id, etc.
Invoke this method to get only the value of a token.
FAQs
Create a authorized connection to Google APIs.
The npm package google-service-account receives a total of 15 weekly downloads. As such, google-service-account popularity was classified as not popular.
We found that google-service-account demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.