Fastify
INFO
Available in >2.0.0
This adapter converts between the Fastify Request and Reply objects and the OAuthRequest and OAuthResponse objects of this package.
Functions
ts
requestFromFastify(req: FastifyRequest): OAuthRequestts
responseFromFastify(res: FastifyReply): OAuthResponsets
handleFastifyReply(fastifyReply: FastifyReply, oauthResponse: OAuthResponse): voidts
handleFastifyError(e: unknown | OAuthException, reply: FastifyReply): voidExample
ts
import { requestFromFastify, handleFastifyReply, handleFastifyError } from "@jmondi/oauth2-server/fastify";
import fastify from 'fastify'
import type { FastifyRequest, FastifyReply } from 'fastify'
const app = fastify()
// ...
app.post('/oauth2/token', async (request: FastifyRequest, reply: FastifyReply) => {
const authorizationServer = request.server.authorizationServer;
try {
const oauthResponse = await authorizationServer
.respondToAccessTokenRequest(requestFromFastify(request));
handleFastifyReply(reply, oauthResponse);
} catch (e) {
handleFastifyError(e, reply);
}
});