Skip to content

Commit 58af8d3

Browse files
committed
fixed README
1 parent 975db73 commit 58af8d3

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
node-version: 18
1919
cache: 'pnpm'
2020
- run: pnpm install --frozen-lockfile
21-
- run: pnpm test
21+
- run: pnpm test-with-emulator
2222
env:
2323
CI: true
2424
eslint:

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ $ npm i firebase-auth-cloudflare-workers
110110

111111
## API
112112

113-
### `Auth.getOrInitialize(projectId: string, keyStore: KeyStorer): Auth`
113+
### `Auth.getOrInitialize(projectId: string, keyStore: KeyStorer, credential?: Credential): Auth`
114114

115115
Auth is created as a singleton object. This is because the Module Worker syntax only use environment variables at the time of request.
116116

117117
- `projectId` specifies the ID of the project for which firebase auth is used.
118118
- `keyStore` is used to cache the public key used to validate the Firebase ID token (JWT).
119+
- `credential` is an optional. This is used to utilize Admin APIs such as `createSessionCookie`. Currently, you can specify `ServiceAccountCredential` class, which allows you to use a service account.
119120

120121
See official document for project ID: https://firebase.google.com/docs/projects/learn-more#project-identifiers
121122

@@ -125,6 +126,7 @@ Verifies a Firebase ID token (JWT). If the token is valid, the promise is fulfil
125126

126127
See the [ID Token section of the OpenID Connect spec](http://openid.net/specs/openid-connect-core-1_0.html#IDToken) for more information about the specific properties below.
127128

129+
- `idToken` The ID token to verify.
128130
- `env` is an optional parameter. but this is using to detect should use emulator or not.
129131

130132
### `WorkersKVStoreSingle.getOrInitialize(cacheKey: string, cfKVNamespace: KVNamespace): WorkersKVStoreSingle`
@@ -138,6 +140,25 @@ This is implemented `KeyStorer` interface.
138140
- `cacheKey` specifies the key of the public key cache.
139141
- `cfKVNamespace` specifies the KV namespace which is bound your workers.
140142

143+
### `createSessionCookie(idToken: string, sessionCookieOptions: SessionCookieOptions, env?: EmulatorEnv): Promise<string>`
144+
145+
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.
146+
147+
- `idToken` The Firebase ID token to exchange for a session cookie.
148+
- `sessionCookieOptions` The session cookie options which includes custom session duration.
149+
- `env` is an optional parameter. but this is using to detect should use emulator or not.
150+
151+
**Required** service acccount credential to use this API. You need to set the credentials with `Auth.getOrInitialize`.
152+
153+
### `verifySessionCookie(sessionCookie: string, env?: EmulatorEnv): Promise<FirebaseIdToken>`
154+
155+
Verifies a Firebase session cookie. Returns a Promise with the cookie claims. Rejects the promise if the cookie could not be verified.
156+
157+
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.
158+
159+
- `sessionCookie` The session cookie to verify.
160+
- `env` is an optional parameter. but this is using to detect should use emulator or not.
161+
141162
### `emulatorHost(env?: EmulatorEnv): string | undefined`
142163

143164
Returns the host of your Firebase Auth Emulator. For example, this case returns `"127.0.0.1:9099"` if you configured like below.
@@ -193,6 +214,12 @@ I put an [example](https://github.com/Code-Hex/firebase-auth-cloudflare-workers/
193214
7. Get jwt for created user by `$ curl -s http://localhost:8787/get-jwt | jq .idToken -r`
194215
8. Try authorization with user jwt `$ curl http://localhost:8787/ -H 'Authorization: Bearer PASTE-JWT-HERE'`
195216

217+
### for Session Cookie
218+
219+
You can try session cookie with your browser.
220+
221+
Access to `/admin/login` after started up Emulator and created an account (email: `[email protected]` password: `test1234`).
222+
196223
## Todo
197224

198225
### Non-required service account key.

0 commit comments

Comments
 (0)