Skip to main content

Vanilla

info

Available in >3.4.0

This adapter provides utility functions to convert between vanilla JavaScript Request and Response objects and the OAuthRequest/OAuthResponse objects used by the this package.

Functions

responseFromVanilla(res: Response): OAuthResponse
requestFromVanilla(req: Request): Promise<OAuthRequest>
responseToVanilla(oauthResponse: OAuthResponse): Response

Example

import { requestFromVanilla, responseToVanilla } from "@jmondi/oauth2-server/vanilla";

import { Hono } from 'hono'
const app = new Hono()

// ...

app.post('/oauth2/token', async (c) => {
const authorizationServer = c.get("authorization_server");

const oauthResponse = await authorizationServer
.respondToAccessTokenRequest(await requestFromVanilla(request))
.catch(e => {
error(400, e.message);
});

return responseToVanilla(oauthResponse);
});

export default app