-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* main: fix: move all crypto imports to import directly crypto not node:crypto fix: add vanilla adapters to jsr exports ops: bump pnpm setup docs: update adapter docs and improve homepage
- Loading branch information
Showing
35 changed files
with
513 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,47 @@ | ||
# Express | ||
|
||
[Express](https://expressjs.com/) | ||
:::info | ||
|
||
Adapts the [Express.Request](https://expressjs.com/en/api.html#req) and [Express.Response](https://expressjs.com/en/api.html#res) for use with `@jmondi/oauth2-server`. | ||
Available in >2.0.0 | ||
|
||
```typescript | ||
import { | ||
requestFromExpress, | ||
handleExpressResponse, | ||
handleExpressError, | ||
} from "@jmondi/oauth2-server/express"; | ||
``` | ||
::: | ||
|
||
```typescript | ||
requestFromExpress(req: Express.Request): OAuthRequest; | ||
``` | ||
This adapter provides utility functions to convert between Express [Request](https://expressjs.com/en/api.html#req) and [Response](https://expressjs.com/en/api.html#res) objects and the `OAuthRequest`/`OAuthResponse` objects used by this package. | ||
|
||
Helper function to return an OAuthRequest from an `Express.Request`. | ||
## Functions | ||
|
||
```typescript | ||
handleExpressResponse(expressResponse: Express.Response, oauthResponse: OAuthResponse): void; | ||
```ts | ||
requestFromExpress(req: Express.Request): OAuthRequest | ||
``` | ||
|
||
Helper function that handles the express response after authorization. | ||
```ts | ||
handleExpressResponse(expressResponse: Express.Response, oauthResponse: OAuthResponse): void | ||
``` | ||
|
||
```typescript | ||
handleExpressError(res: Express.Response, e: unknown | OAuthException): void; | ||
```ts | ||
handleExpressError(res: Express.Response, e: unknown | OAuthException): void | ||
``` | ||
|
||
Helper function that handles the express response if an error was thrown. | ||
## Example | ||
|
||
```ts | ||
import { requestFromExpress, handleExpressResponse, handleExpressError } from "@jmondi/oauth2-server/express"; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
// ... | ||
|
||
app.post('/oauth2/token', async (req: express.Request, res: express.Response) => { | ||
const authorizationServer = req.app.get('authorization_server'); | ||
|
||
try { | ||
const oauthResponse = await authorizationServer | ||
.respondToAccessTokenRequest(requestFromExpress(req)); | ||
|
||
handleExpressResponse(res, oauthResponse); | ||
} catch (e) { | ||
handleExpressError(res, e); | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,48 @@ | ||
# Fastify | ||
|
||
Adapts the [Fastify.Request](https://fastify.dev/docs/latest/Reference/Request/) and [Fastify.Reply](https://fastify.dev/docs/latest/Reference/Reply/) for use with `@jmondi/oauth2-server`. | ||
|
||
```typescript | ||
import { | ||
requestFromFastify, | ||
handleFastifyReply, | ||
handleFastifyError, | ||
} from "@jmondi/oauth2-server/fastify"; | ||
``` | ||
:::info | ||
|
||
The following functions are imported directly from the adapter instead of the root package. | ||
Available in >2.0.0 | ||
|
||
::: | ||
|
||
```typescript | ||
requestFromFastify(req: FastifyRequest): OAuthRequest; | ||
``` | ||
|
||
Helper function to return an OAuthRequest from an `FastifyRequest`. | ||
This adapter provides utility functions to convert between Fastify [Request](https://fastify.dev/docs/latest/Reference/Request/) and [Reply](https://fastify.dev/docs/latest/Reference/Reply/) objects and the `OAuthRequest`/`OAuthResponse` objects used by this package. | ||
|
||
```typescript | ||
handleFastifyReply(fastifyReply: FasitfyReply, oauthResponse: OAuthResponse): void; | ||
## Functions | ||
|
||
```ts | ||
requestFromFastify(req: FastifyRequest): OAuthRequest | ||
``` | ||
|
||
Helper function that handles the express response after authorization. | ||
```ts | ||
handleFastifyReply(fastifyReply: FastifyReply, oauthResponse: OAuthResponse): void | ||
``` | ||
|
||
```typescript | ||
handleFastifyError(reply: FasitfyReply, e: unknown | OAuthException): void; | ||
```ts | ||
handleFastifyError(reply: FastifyReply, e: unknown | OAuthException): void | ||
``` | ||
|
||
Helper function that handles the express response if an error was thrown. | ||
## Example | ||
|
||
```ts | ||
import { requestFromFastify, handleFastifyReply, handleFastifyError } from "@jmondi/oauth2-server/fastify"; | ||
import fastify from 'fastify' | ||
|
||
const app = fastify() | ||
|
||
// ... | ||
|
||
app.post('/oauth2/token', async (request: fastify.Request, reply: fastify.Reply) => { | ||
const authorizationServer = request.server.authorizationServer; | ||
|
||
try { | ||
const oauthResponse = await authorizationServer | ||
.respondToAccessTokenRequest(requestFromFastify(request)); | ||
|
||
handleFastifyReply(reply, oauthResponse); | ||
} catch (e) { | ||
handleFastifyError(reply, e); | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.