feat: add first party Deno KV OAuth plugin (#1774)
This commit is contained in:
@@ -11,6 +11,62 @@ description: Easily integrate OAuth 2.0 to your Fresh project with Deno KV OAuth
|
||||
> change**. See [the documentation](https://deno.land/x/deno_kv_oauth) for
|
||||
> further details.
|
||||
|
||||
## Getting Started with the Official Fresh Plugin
|
||||
|
||||
> Note: The minimum required version for plugins in Fresh is 1.3.0
|
||||
|
||||
If you're not performing anything special in the sign-in, sign-out and callback
|
||||
handlers, you can add the Fresh plugin to your project. This automatically
|
||||
handles `GET /oauth/signin`, `GET /oauth/callback` and `GET /oauth/signout`
|
||||
routes.
|
||||
|
||||
1. Create your OAuth 2.0 application for your given provider.
|
||||
|
||||
2. Create your
|
||||
[pre-configured](https://deno.land/x/deno_kv_oauth#pre-configured-oauth-20-clients)
|
||||
or
|
||||
[custom OAuth 2.0 client instance](https://deno.land/x/deno_kv_oauth#custom-oauth-20-client)
|
||||
and configure Fresh to use the plugin.
|
||||
|
||||
```ts
|
||||
// main.ts
|
||||
import { start } from "$fresh/server.ts";
|
||||
import kvOAuthPlugin from "$fresh/plugins/kv_oauth.ts";
|
||||
import { createGitHubOAuth2Client } from "https://deno.land/x/deno_kv_oauth@$VERSION/mod.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
|
||||
await start(manifest, {
|
||||
plugins: [
|
||||
kvOAuthPlugin(createGitHubOAuth2Client()),
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
3. ⚠️ While Deno KV is still **experimental** you need to add the `--unstable`
|
||||
option to the `start` task in the `deno.json` file.
|
||||
|
||||
```json
|
||||
"start": "deno run -A --watch=static/,routes/ --unstable dev.ts",
|
||||
```
|
||||
|
||||
4. Start your project with the necessary environment variables.
|
||||
|
||||
```sh
|
||||
GITHUB_CLIENT_ID=xxx GITHUB_CLIENT_SECRET=xxx deno task start
|
||||
```
|
||||
|
||||
If you require more advanced setups, you can create your own plugin. For more
|
||||
information, see:
|
||||
|
||||
- The [source code](src/fresh_plugin.ts) for `kvOAuthPlugin()`
|
||||
- The [Plugin documentation](https://fresh.deno.dev/docs/concepts/plugins) for
|
||||
Fresh
|
||||
- The
|
||||
[Fresh + Deno KV OAuth demo](https://github.com/denoland/fresh-deno-kv-oauth-demo)
|
||||
which uses the Fresh plugin
|
||||
- [Deno SaaSKit](https://saaskit.deno.dev/)'s custom
|
||||
[plugin implementation](https://github.com/denoland/saaskit/blob/3accffdc44c2d2eb6dba28126f8d4cb525eba340/plugins/kv_oauth.ts)
|
||||
|
||||
## Getting Started
|
||||
|
||||
This example uses GitHub as the OAuth 2.0 provider. However there is a suite of
|
||||
|
||||
Reference in New Issue
Block a user