Merge pull request #5 from honojs/fix/documentation

fixed documentation
pull/34/head
Kei Kamikawa 2022-07-28 15:53:27 +09:00 committed by GitHub
commit 08d9e7af32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 22 deletions

View File

@ -1,40 +1,62 @@
# Hello middleware for Hono # Hono Firebase Auth middleware for Cloudflare Workers.
An example project of the third-party middleware for [Hono](https://github.com/honojs/hono). This is a Firebase Auth middleware library for [Hono](https://github.com/honojs/hono) which is used [firebase-auth-cloudflare-workers](https://github.com/Code-Hex/firebase-auth-cloudflare-workers).
This middleware add `X-Message` header to the Response.
## Usage Currently only Cloudflare Workers are supported officially. However, it may work in other environments as well, so please let us know in an issue if it works.
## Synopsis
```ts ```ts
import { hello } from '@honojs/hello' import { Hono } from "hono";
import { Hono } from 'hono' import { VerifyFirebaseAuthConfig, VerifyFirebaseAuthEnv, verifyFirebaseAuth, getFirebaseToken } from "@honojs/firebase-auth";
const app = new Hono() const config: VerifyFirebaseAuthConfig = {
// specify your firebase project ID.
projectId: "your-project-id",
}
app.use('*', hello('Hello!! Hono!!')) // Or you can specify here the extended VerifyFirebaseAuthEnv type.
app.get('/', (c) => c.text('foo')) const app = new Hono<VerifyFirebaseAuthEnv>()
// set middleware
app.use("*", verifyFirebaseAuth(config));
app.get("/hello", (c) => {
const idToken = getFirebaseToken(c) // get id-token object.
return c.json(idToken)
});
export default app export default app
``` ```
## Deno ## Config (`VerifyFirebaseAuthConfig`)
```ts ### `projectId: string` (**required**)
import { serve } from 'https://deno.land/std/http/server.ts'
import { hello } from 'https://deno.land/x/hono_hello/mod.ts'
import { Hono } from 'https://deno.land/x/hono/mod.ts'
const app = new Hono() This field indicates your firebase project ID.
app.use('*', hello('Hello!! Hono!!')) ### `authorizationHeaderKey?: string` (optional)
app.get('/', (c) => c.text('foo'))
serve(app.fetch) Based on this configuration, the JWT created by firebase auth is looked for in the HTTP headers. The default is "Authorization".
```
### `keyStore?: KeyStorer` (optional)
This is used to cache the public key used to validate the Firebase ID token (JWT). This KeyStorer type has been defined in [firebase-auth-cloudflare-workers](https://github.com/Code-Hex/firebase-auth-cloudflare-workers/tree/main#keystorer) library.
If you don't specify the field, this library uses [WorkersKVStoreSingle](https://github.com/Code-Hex/firebase-auth-cloudflare-workers/tree/main#workerskvstoresinglegetorinitializecachekey-string-cfkvnamespace-kvnamespace-workerskvstoresingle) instead. You must fill in the fields defined in `VerifyFirebaseAuthEnv`.
### `keyStoreInitializer?: (c: Context) => KeyStorer` (optional)
Use this when initializing KeyStorer and environment variables, etc. are required.
If you don't specify the field, this library uses [WorkersKVStoreSingle](https://github.com/Code-Hex/firebase-auth-cloudflare-workers/tree/main#workerskvstoresinglegetorinitializecachekey-string-cfkvnamespace-kvnamespace-workerskvstoresingle) instead. You must fill in the fields defined in `VerifyFirebaseAuthEnv`.
### `disableErrorLog?: boolean` (optional)
Throws an exception if JWT validation fails. By default, this is output to the error log, but if you don't expect it, use this.
## Author ## Author
Yusuke Wada <https://github.com/yusukebe> codehex <https://github.com/Code-Hex>
## License ## License

View File

@ -1,7 +1,10 @@
import { getFirebaseToken } from "./../src/index";
import { Auth, KeyStorer } from "firebase-auth-cloudflare-workers"; import { Auth, KeyStorer } from "firebase-auth-cloudflare-workers";
import { Hono } from "hono"; import { Hono } from "hono";
import { VerifyFirebaseAuthEnv, verifyFirebaseAuth } from "../src"; import {
VerifyFirebaseAuthEnv,
verifyFirebaseAuth,
getFirebaseToken,
} from "../src";
describe("verifyFirebaseAuth middleware", () => { describe("verifyFirebaseAuth middleware", () => {
const emulatorHost = "127.0.0.1:9099"; const emulatorHost = "127.0.0.1:9099";