firebase-auth-cloudflare-workers
Advanced tools
Comparing version 1.2.1 to 1.2.2
/// <reference types="@cloudflare/workers-types" /> | ||
import { BaseAuth } from './auth'; | ||
import { AuthApiClient } from './auth-api-requests'; | ||
import type { RetryConfig } from './client'; | ||
import type { Credential } from './credential'; | ||
@@ -11,4 +13,6 @@ import type { KeyStorer } from './key-store'; | ||
export type { FirebaseIdToken } from './token-verifier'; | ||
export type { RetryConfig }; | ||
export declare class Auth extends BaseAuth { | ||
private static instance?; | ||
private static withCredential?; | ||
private constructor(); | ||
@@ -22,1 +26,6 @@ static getOrInitialize(projectId: string, keyStore: KeyStorer, credential?: Credential): Auth; | ||
} | ||
export declare class AdminAuthApiClient extends AuthApiClient { | ||
private static instance?; | ||
private constructor(); | ||
static getOrInitialize(projectId: string, credential: Credential, retryConfig?: RetryConfig): AdminAuthApiClient; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WorkersKVStoreSingle = exports.Auth = exports.useEmulator = exports.emulatorHost = exports.ServiceAccountCredential = void 0; | ||
exports.AdminAuthApiClient = exports.WorkersKVStoreSingle = exports.Auth = exports.useEmulator = exports.emulatorHost = exports.ServiceAccountCredential = void 0; | ||
const auth_1 = require("./auth"); | ||
const auth_api_requests_1 = require("./auth-api-requests"); | ||
const key_store_1 = require("./key-store"); | ||
@@ -13,2 +14,3 @@ var credential_1 = require("./credential"); | ||
static instance; | ||
static withCredential; | ||
constructor(projectId, keyStore, credential) { | ||
@@ -18,4 +20,10 @@ super(projectId, keyStore, credential); | ||
static getOrInitialize(projectId, keyStore, credential) { | ||
if (!Auth.withCredential && credential !== undefined) { | ||
Auth.withCredential = new Auth(projectId, keyStore, credential); | ||
} | ||
if (Auth.withCredential) { | ||
return Auth.withCredential; | ||
} | ||
if (!Auth.instance) { | ||
Auth.instance = new Auth(projectId, keyStore, credential); | ||
Auth.instance = new Auth(projectId, keyStore); | ||
} | ||
@@ -39,1 +47,14 @@ return Auth.instance; | ||
exports.WorkersKVStoreSingle = WorkersKVStoreSingle; | ||
class AdminAuthApiClient extends auth_api_requests_1.AuthApiClient { | ||
static instance; | ||
constructor(projectId, credential, retryConfig) { | ||
super(projectId, credential, retryConfig); | ||
} | ||
static getOrInitialize(projectId, credential, retryConfig) { | ||
if (!AdminAuthApiClient.instance) { | ||
AdminAuthApiClient.instance = new AdminAuthApiClient(projectId, credential, retryConfig); | ||
} | ||
return AdminAuthApiClient.instance; | ||
} | ||
} | ||
exports.AdminAuthApiClient = AdminAuthApiClient; |
@@ -1,1 +0,1 @@ | ||
export declare const version = "1.2.1"; | ||
export declare const version = "1.2.2"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '1.2.1'; | ||
exports.version = '1.2.2'; |
import { BaseAuth } from './auth'; | ||
import { AuthApiClient } from './auth-api-requests'; | ||
import { WorkersKVStore } from './key-store'; | ||
@@ -7,2 +8,3 @@ export { ServiceAccountCredential } from './credential'; | ||
static instance; | ||
static withCredential; | ||
constructor(projectId, keyStore, credential) { | ||
@@ -12,4 +14,10 @@ super(projectId, keyStore, credential); | ||
static getOrInitialize(projectId, keyStore, credential) { | ||
if (!Auth.withCredential && credential !== undefined) { | ||
Auth.withCredential = new Auth(projectId, keyStore, credential); | ||
} | ||
if (Auth.withCredential) { | ||
return Auth.withCredential; | ||
} | ||
if (!Auth.instance) { | ||
Auth.instance = new Auth(projectId, keyStore, credential); | ||
Auth.instance = new Auth(projectId, keyStore); | ||
} | ||
@@ -31,1 +39,13 @@ return Auth.instance; | ||
} | ||
export class AdminAuthApiClient extends AuthApiClient { | ||
static instance; | ||
constructor(projectId, credential, retryConfig) { | ||
super(projectId, credential, retryConfig); | ||
} | ||
static getOrInitialize(projectId, credential, retryConfig) { | ||
if (!AdminAuthApiClient.instance) { | ||
AdminAuthApiClient.instance = new AdminAuthApiClient(projectId, credential, retryConfig); | ||
} | ||
return AdminAuthApiClient.instance; | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
export const version = '1.2.1'; | ||
export const version = '1.2.2'; |
{ | ||
"name": "firebase-auth-cloudflare-workers", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Zero-dependencies firebase auth library for Cloudflare Workers.", | ||
@@ -59,4 +59,5 @@ "author": "codehex", | ||
"prepublish": "run-p build:*", | ||
"wrangler": "wrangler" | ||
"wrangler": "wrangler", | ||
"version": "pnpm run build && git add -A src/version.ts" | ||
} | ||
} |
@@ -132,15 +132,13 @@ # firebase-auth-cloudflare-workers | ||
### `WorkersKVStoreSingle.getOrInitialize(cacheKey: string, cfKVNamespace: KVNamespace): WorkersKVStoreSingle` | ||
### `authObj.verifySessionCookie(sessionCookie: string, env?: EmulatorEnv): Promise<FirebaseIdToken>` | ||
WorkersKVStoreSingle is created as a singleton object. This is because the Module Worker syntax only use environment variables at the time of request. | ||
Verifies a Firebase session cookie. Returns a Promise with the cookie claims. Rejects the promise if the cookie could not be verified. | ||
This caches the public key used to verify the Firebase ID token in the [Workers KV](https://developers.cloudflare.com/workers/runtime-apis/kv/). | ||
See [Verify Session Cookies](https://firebase.google.com/docs/auth/admin/manage-cookies#verify_session_cookie_and_check_permissions) for code samples and detailed documentation. | ||
This is implemented `KeyStorer` interface. | ||
- `sessionCookie` The session cookie to verify. | ||
- `env` is an optional parameter. but this is using to detect should use emulator or not. | ||
- `cacheKey` specifies the key of the public key cache. | ||
- `cfKVNamespace` specifies the KV namespace which is bound your workers. | ||
### `authObj.createSessionCookie(idToken: string, sessionCookieOptions: SessionCookieOptions, env?: EmulatorEnv): Promise<string>` | ||
### `createSessionCookie(idToken: string, sessionCookieOptions: SessionCookieOptions, env?: EmulatorEnv): Promise<string>` | ||
Creates a new Firebase session cookie with the specified options. The created JWT string can be set as a server-side session cookie with a custom cookie policy, and be used for session management. The session cookie JWT will have the same payload claims as the provided ID token. See [Manage Session Cookies](https://firebase.google.com/docs/auth/admin/manage-cookies) for code samples and detailed documentation. | ||
@@ -154,11 +152,21 @@ | ||
### `verifySessionCookie(sessionCookie: string, env?: EmulatorEnv): Promise<FirebaseIdToken>` | ||
### `WorkersKVStoreSingle.getOrInitialize(cacheKey: string, cfKVNamespace: KVNamespace): WorkersKVStoreSingle` | ||
Verifies a Firebase session cookie. Returns a Promise with the cookie claims. Rejects the promise if the cookie could not be verified. | ||
WorkersKVStoreSingle is created as a singleton object. This is because the Module Worker syntax only use environment variables at the time of request. | ||
See [Verify Session Cookies](https://firebase.google.com/docs/auth/admin/manage-cookies#verify_session_cookie_and_check_permissions) for code samples and detailed documentation. | ||
This caches the public key used to verify the Firebase ID token in the [Workers KV](https://developers.cloudflare.com/workers/runtime-apis/kv/). | ||
- `sessionCookie` The session cookie to verify. | ||
- `env` is an optional parameter. but this is using to detect should use emulator or not. | ||
This is implemented `KeyStorer` interface. | ||
- `cacheKey` specifies the key of the public key cache. | ||
- `cfKVNamespace` specifies the KV namespace which is bound your workers. | ||
### `AdminAuthApiClient.getOrInitialize(projectId: string, credential: Credential, retryConfig?: RetryConfig): AdminAuthApiClient` | ||
AdminAuthApiClient is created as a singleton object. This is because the Module Worker syntax only use environment variables at the time of request. | ||
You can send request with the [Admin Auth API](https://cloud.google.com/identity-platform/docs/reference/rest). To generate an access token, you will use the `Credential` class. For instance, if you want to generate an access token from a Service Account JSON, you need to specify `ServiceAccountCredential` as a parameter during initialization. | ||
By specifying the [`roles/firebaseauth.admin`](https://firebase.google.com/docs/projects/iam/roles-predefined-product#app-distro) role to the Service Account, it becomes available for use. If you want finer control over permissions, create a Custom Role based on the [Access Control](https://cloud.google.com/identity-platform/docs/access-control) guide and assign it to the Service Account. | ||
### `emulatorHost(env?: EmulatorEnv): string | undefined` | ||
@@ -165,0 +173,0 @@ |
156293
3608
240