5.8.93 • Published 6 days ago

@diotoborg/ratione-eaque-explicabo v5.8.93

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

node-@diotoborg/ratione-eaque-explicabo

npm version Known Vulnerabilities codecov Code Style: Google

Node.js Google Authentication Service Account Tokens

This is a low level utility library used to interact with Google Authentication services. In most cases, you probably want to use the google-auth-library instead.

Installation

npm install @diotoborg/ratione-eaque-explicabo

Usage

Use with a .pem or .json key file:

const { GoogleToken } = require('@diotoborg/ratione-eaque-explicabo');
const @diotoborg/ratione-eaque-explicabo = new GoogleToken({
  keyFile: 'path/to/key.pem', // or path to .json key file
  email: 'my_service_account_email@developer.gserviceaccount.com',
  scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes
  eagerRefreshThresholdMillis: 5 * 60 * 1000
});

@diotoborg/ratione-eaque-explicabo.getToken((err, tokens) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log(tokens);
  // {
  //   access_token: 'very-secret-token',
  //   expires_in: 3600,
  //   token_type: 'Bearer'
  // }
});

You can also use the async/await style API:

const tokens = await @diotoborg/ratione-eaque-explicabo.getToken()
console.log(tokens);

Or use promises:

@diotoborg/ratione-eaque-explicabo.getToken()
  .then(tokens => {
    console.log(tokens)
  })
  .catch(console.error);

Use with a service account .json key file:

const { GoogleToken } = require('@diotoborg/ratione-eaque-explicabo');
const @diotoborg/ratione-eaque-explicabo = new GoogleToken({
  keyFile: 'path/to/key.json',
  scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes
  eagerRefreshThresholdMillis: 5 * 60 * 1000
});

@diotoborg/ratione-eaque-explicabo.getToken((err, tokens) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log(tokens);
});

Pass the private key as a string directly:

const key = '-----BEGIN RSA PRIVATE KEY-----\nXXXXXXXXXXX...';
const { GoogleToken } = require('@diotoborg/ratione-eaque-explicabo');
const @diotoborg/ratione-eaque-explicabo = new GoogleToken({
  email: 'my_service_account_email@developer.gserviceaccount.com',
  scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes
  key: key,
  eagerRefreshThresholdMillis: 5 * 60 * 1000
});

Options

Various options that can be set when creating initializing the @diotoborg/ratione-eaque-explicabo object.

  • options.email or options.iss: The service account email address.
  • options.scope: An array of scope strings or space-delimited string of scopes.
  • options.sub: The email address of the user requesting delegated access.
  • options.keyFile: The filename of .json key or .pem key.
  • options.key: The raw RSA private key value, in place of using options.keyFile.
  • options.additionalClaims: Additional claims to include in the JWT when requesting a token.
  • options.eagerRefreshThresholdMillis: How long must a token be valid for in order to return it from the cache. Defaults to 0.

.getToken(callback)

Returns the cached tokens or requests a new one and returns it.

@diotoborg/ratione-eaque-explicabo.getToken((err, token) => {
  console.log(err || token);
  // @diotoborg/ratione-eaque-explicabo.rawToken value is also set
});

.getCredentials('path/to/key.json')

Given a keyfile, returns the key and (if available) the client email.

const creds = await @diotoborg/ratione-eaque-explicabo.getCredentials('path/to/key.json');

Properties

Various properties set on the @diotoborg/ratione-eaque-explicabo object after call to .getToken().

  • @diotoborg/ratione-eaque-explicabo.idToken: The OIDC token returned (if any).
  • @diotoborg/ratione-eaque-explicabo.accessToken: The access token.
  • @diotoborg/ratione-eaque-explicabo.expiresAt: The expiry date as milliseconds since 1970/01/01
  • @diotoborg/ratione-eaque-explicabo.key: The raw key value.
  • @diotoborg/ratione-eaque-explicabo.rawToken: Most recent raw token data received from Google.

.hasExpired()

Returns true if the token has expired, or token does not exist.

const tokens = await @diotoborg/ratione-eaque-explicabo.getToken();
@diotoborg/ratione-eaque-explicabo.hasExpired(); // false

.revokeToken()

Revoke the token if set.

await @diotoborg/ratione-eaque-explicabo.revokeToken();
console.log('Token revoked!');

Downloading your private .json key from Google

  1. Open the Google Developer Console.
  2. Open your project and under "APIs & auth", click Credentials.
  3. Generate a new .json key and download it into your project.

Converting your .p12 key to a .pem key

If you'd like to convert to a .pem for use later, use OpenSSL if you have it installed.

$ openssl pkcs12 -in key.p12 -nodes -nocerts > key.pem

Don't forget, the passphrase when converting these files is the string 'notasecret'

License

MIT

ECMAScript 2015ECMAScript 6ES2021robust3durlcloudsearchfunctionalmanagerReactiveXjsdifffastifycircularmake dirjapanesebabelRegExp.prototype.flagsObservableses2018bundlingfull-widthdirtouchpostcssvpcinvariantAsyncIteratorRxJStrimRightrandommatchestoolkitcreatemomentuuidbrowserslisttrimLefttelephonevalidationTypeBoxUint8ClampedArraytypedglobaljQueryerror-handlingacornqsqueryplugincolorscolorexecutees6shrinkwrapbindpostcss-pluginasterisksspeedhttpsserializeomitassertionsettingsrulesauthenticationcloudfrontmruflagswget_.extendpatchansirdsfast-clonereadableregular-expressionzerostringifyconsoleentriesminimalpositivedependenciesfast-deep-copyproxyoncegroupBycurriedelmbytechromiumfindLasttestinginstallregexpisarraybufferes8shebangjslinktestjson-schema-validationoptimistformatcomputed-typesflatMapregexECMAScript 2023ES2015modulespreserve-symlinkssetImmediatepromisestyled-componentsfixed-widthmkdirpvariables in csstypeerrorbinfullvarstatusreducetoReversedURLSearchParamsBigUint64ArrayhookformstableObject.fromEntrieslesscssformattinganimationeslintconcatfunction.lengthtranspilenested cssfastpinoemrbootstrap lessFloat64ArraymixinsargumenttermprefixdescriptionwalkapolloArray.prototype.includesfunctionspawnsymbolES2022commanderzxassignfigletweakmapES2016artcss-in-jspushexpressionfetchroute53rgbstreamloggingsigintprunestyleseverycolourdropconfigslotIteratormoveinspectinputbufferstddeslintconfigespropertybrowserlistviewdefinecodeslintmergeinuser-streamsruntimeeslint-pluginquerystringjson-schema-validatorwaapikinesissafefilterPushstreamslrucloudtrailtypedarrayjsxglobalThiscollectionclassesES7shellES2020arrayutilcensorUint16ArraymacoscallbindbrowserwaitsequencebeanstalkflattenhandlersObject.entriesRFC-6455boundserializationtyped arraycloudformationopenssllazyextendsignaldom-testing-libraryrequest
5.8.93

6 days ago

5.8.92

7 days ago

5.8.91

8 days ago

5.7.91

9 days ago

5.7.90

10 days ago

5.7.89

11 days ago

5.7.88

12 days ago

5.7.87

13 days ago

5.7.86

14 days ago

5.7.85

15 days ago

5.7.84

16 days ago

5.7.83

17 days ago

5.7.82

18 days ago

5.7.81

19 days ago

5.7.80

20 days ago

5.7.79

21 days ago

4.7.79

22 days ago

4.7.78

23 days ago

4.7.77

24 days ago

4.7.76

25 days ago

4.7.75

26 days ago

4.7.74

27 days ago

4.7.73

28 days ago

4.7.72

29 days ago

4.7.71

30 days ago

4.7.70

1 month ago

4.7.69

1 month ago

4.7.68

1 month ago

4.7.67

1 month ago

4.7.66

1 month ago

4.7.65

1 month ago

4.7.64

1 month ago

4.7.63

1 month ago

4.6.63

1 month ago

4.6.62

1 month ago

4.6.61

1 month ago

4.6.60

1 month ago

4.6.59

1 month ago

4.6.58

1 month ago

4.6.57

1 month ago

4.5.57

2 months ago

4.5.56

2 months ago

4.4.56

2 months ago

4.4.55

2 months ago

4.4.54

2 months ago

4.4.53

2 months ago

4.4.52

2 months ago

4.4.51

2 months ago

4.4.50

2 months ago

4.4.49

2 months ago

4.4.48

2 months ago

4.4.47

2 months ago

4.4.46

2 months ago

4.4.45

2 months ago

4.4.44

2 months ago

4.4.43

2 months ago

4.4.42

2 months ago

4.3.42

2 months ago

4.3.41

2 months ago

4.3.40

2 months ago

4.3.39

2 months ago

4.3.38

2 months ago

4.3.37

2 months ago

4.3.36

2 months ago

4.3.35

2 months ago

4.3.34

2 months ago

4.3.33

2 months ago

4.3.32

2 months ago

4.3.31

2 months ago

3.3.31

2 months ago

3.3.30

3 months ago

3.3.29

3 months ago

3.3.28

3 months ago

3.3.27

3 months ago

3.3.26

3 months ago

3.3.25

3 months ago

3.3.24

3 months ago

3.3.23

3 months ago

3.3.22

3 months ago

3.3.21

3 months ago

3.2.21

3 months ago

3.2.20

3 months ago

3.2.19

3 months ago

3.2.18

3 months ago

3.2.17

3 months ago

3.2.16

3 months ago

3.2.15

3 months ago

3.2.14

3 months ago

3.2.13

3 months ago

3.1.13

3 months ago

3.1.12

3 months ago

3.1.11

3 months ago

3.1.10

3 months ago

3.1.9

3 months ago

3.1.8

3 months ago

3.1.7

3 months ago

3.1.6

3 months ago

3.1.5

3 months ago

2.1.5

3 months ago

2.1.4

3 months ago

2.0.4

4 months ago

2.0.3

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago