Skip to content

v2.0.0 Fastify!

Compare
Choose a tag to compare
@jasonraimondi jasonraimondi released this 12 Sep 05:22

I was trying to do this as a minor release with no breaking changes, thus the 1.3.0-rc.x tags, but I ended up embracing reality and just marking this as a major version with two small breaking changes.

  • Breaking - The CodeChallengeMethod interface was updated from "s265" to "S265" and the AuthorizationServer is now checking explicitly for this value. Fixes #25
  • Breaking - The handleResponse and handleError has been replaced with adapter specific helpers. These helpers were/are optional to use in the first place, but if they are used, you must now use the framework specific adapters. Please see the docs for more information.
// before only express was supported
import { handleResponse, handleError } from "@jmondi/oauth2-server";

// now there are separate adapters for Express and Fastify
import { handleExpressResponse, handleExpressError } from "@jmondi/oauth2-server/express";
import { handleFastifyReply, handleFastifyError } from "@jmondi/oauth2-server/fastify";
  • Feature - Fastify is now supported! Use the new Fastify adapters to create an OAuthRequest and OAuthResponse for the AuthorizationServer. See prisma_fastify example.
import { responseFromFastify, requestFromFastify } from "@jmondi/oauth2-server/fastify"

const request = requestFromFastify(req);
const response = responseFromFastify(res);

const authRequest = await authorizationServer.validateAuthorizationRequest(request);
const oauthResponse = await authorizationServer.respondToAccessTokenRequest(request, response);
  • Optional Change for Express - The OAuthRequest constructor is compatible with an Express Request and Response. The new helper function provides better typing for creation, and allows for similar creation patterns for Fastify.
// previously
const request = new OAuthRequest(req);
const authRequest = await authorizationServer.validateAuthorizationRequest(request);

// now
import { responseFromExpress, requestFromExpress } from "@jmondi/oauth2-server/express"

const request = requestFromExpress(req);
const authRequest = await authorizationServer.validateAuthorizationRequest(request);