Vanilla
INFO
Available in >3.4.0
This adapter converts between the native JavaScript Request and Response objects and the OAuthRequest and OAuthResponse objects of this package.
Functions
ts
responseFromVanilla(res: Response): OAuthResponsets
requestFromVanilla(req: Request): Promise<OAuthRequest>ts
responseToVanilla(oauthResponse: OAuthResponse): Responsets
handleVanillaError(e: unknown | OAuthException): OAuthResponseExample
ts
import { requestFromVanilla, responseToVanilla, handleVanillaError } 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");
try {
const oauthResponse = await authorizationServer
.respondToAccessTokenRequest(await requestFromVanilla(c.req.raw));
return responseToVanilla(oauthResponse);
} catch (e) {
return responseToVanilla(handleVanillaError(e));
}
});
export default app