Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 19
cache: "yarn"
cache: 'yarn'

# Install dependencies
- run: yarn config set enableGlobalCache false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_lint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# GitHub Actions workflow
# https://help.github.com/actions

name: "conventionalcommits.org"
name: 'conventionalcommits.org'

on:
pull_request:
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
printWidth: 90
semi: false
trailingComma: 'all'
singleQuote: true
jsxBracketSameLine: false
arrowParens: 'always'
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ $ yarn add web-auth-library
**NOTE**: The `credentials` argument in the examples below is expected to be a serialized JSON string of a [Google Cloud service account key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys), `apiKey` is Google Cloud API Key (Firebase API Key), and `projectId` is a Google Cloud project ID.

```ts
import { verifyIdToken } from "web-auth-library/google";
import { verifyIdToken } from 'web-auth-library/google'

const token = await verifyIdToken({
idToken,
credentials: env.GOOGLE_CLOUD_CREDENTIALS,
});
})

// => {
// iss: 'https://securetoken.google.com/example',
Expand All @@ -57,43 +57,40 @@ const token = await verifyIdToken({
### Create an access token for accessing [Google Cloud APIs](https://developers.google.com/apis-explorer)

```ts
import { getAccessToken } from "web-auth-library/google";
import { getAccessToken } from 'web-auth-library/google'

// Generate a short lived access token from the service account key credentials
const accessToken = await getAccessToken({
credentials: env.GOOGLE_CLOUD_CREDENTIALS,
scope: "https://www.googleapis.com/auth/cloud-platform",
});
scope: 'https://www.googleapis.com/auth/cloud-platform',
})

// Make a request to one of the Google's APIs using that token
const res = await fetch(
"https://cloudresourcemanager.googleapis.com/v1/projects",
{
headers: { Authorization: `Bearer ${accessToken}` },
}
);
const res = await fetch('https://cloudresourcemanager.googleapis.com/v1/projects', {
headers: { Authorization: `Bearer ${accessToken}` },
})
```

## Create a custom ID token using Service Account credentials

```ts
import { getIdToken } from "web-auth-library/google";
import { getIdToken } from 'web-auth-library/google'

const idToken = await getIdToken({
credentials: env.GOOGLE_CLOUD_CREDENTIALS,
audience: "https://example.com",
});
audience: 'https://example.com',
})
```

## An alternative way passing credentials

Instead of passing credentials via `options.credentials` argument, you can also let the library pick up credentials from the list of environment variables using standard names such as `GOOGLE_CLOUD_CREDENTIALS`, `GOOGLE_CLOUD_PROJECT`, `FIREBASE_API_KEY`, for example:

```ts
import { verifyIdToken } from "web-auth-library/google";
import { verifyIdToken } from 'web-auth-library/google'

const env = { GOOGLE_CLOUD_CREDENTIALS: "..." };
const token = await verifyIdToken({ idToken, env });
const env = { GOOGLE_CLOUD_CREDENTIALS: '...' }
const token = await verifyIdToken({ idToken, env })
```

## Optimize cache renewal background tasks
Expand Down
19 changes: 0 additions & 19 deletions core/error.ts

This file was deleted.

36 changes: 0 additions & 36 deletions google/accessToken.test.ts

This file was deleted.

199 changes: 0 additions & 199 deletions google/accessToken.ts

This file was deleted.

Loading