From e0d3c16062cad14b65bdc0f87449edb732a6a064 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 25 Aug 2023 23:25:30 +0200 Subject: [PATCH 1/2] Use `@types/simple-oauth2` instead of redoing it --- package.json | 1 + types/index.d.ts | 46 +++++++--------------------------------------- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 0f6a964..4f15b97 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "dependencies": { "@fastify/cookie": "^9.0.4", + "@types/simple-oauth2": "^5.0.4", "fastify-plugin": "^4.5.1", "simple-oauth2": "^5.0.0" }, diff --git a/types/index.d.ts b/types/index.d.ts index 486aaf8..7047fad 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,5 +1,6 @@ import { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'; import { CookieSerializeOptions } from "@fastify/cookie"; +import { ModuleOptions } from 'simple-oauth2'; interface FastifyOauth2 extends FastifyPluginCallback { APPLE_CONFIGURATION: fastifyOauth2.ProviderConfiguration; @@ -69,47 +70,14 @@ declare namespace fastifyOauth2 { revokeAll(): Promise; } - export interface ProviderConfiguration { - /** String used to set the host to request the tokens to. Required. */ - tokenHost: string; - /** String path to request an access token. Default to /oauth/token. */ - tokenPath?: string | undefined; - /** String path to revoke an access token. Default to /oauth/revoke. */ - revokePath?: string | undefined; - /** String used to set the host to request an "authorization code". Default to the value set on auth.tokenHost. */ - authorizeHost?: string | undefined; - /** String path to request an authorization code. Default to /oauth/authorize. */ - authorizePath?: string | undefined; - } + // Can't extend ModuleOptions["auth"] directly + type SimpleOauth2ProviderConfiguration = ModuleOptions["auth"]; + // Kept for backwards compatibility + export interface ProviderConfiguration extends SimpleOauth2ProviderConfiguration {} - export interface Credentials { - client: { - /** Service registered client id. Required. */ - id: string; - /** Service registered client secret. Required. */ - secret: string; - /** Parameter name used to send the client secret. Default to client_secret. */ - secretParamName?: string | undefined; - /** Parameter name used to send the client id. Default to client_id. */ - idParamName?: string | undefined; - }; + // Kept for backwards compatibility + export interface Credentials extends ModuleOptions { auth: ProviderConfiguration; - /** - * Used to set global options to the internal http library (wreck). - * All options except baseUrl are allowed - * Defaults to header.Accept = "application/json" - */ - http?: {} | undefined; - options?: { - /** Format of data sent in the request body. Defaults to form. */ - bodyFormat?: "json" | "form" | undefined; - /** - * Indicates the method used to send the client.id/client.secret authorization params at the token request. - * If set to body, the bodyFormat option will be used to format the credentials. - * Defaults to header - */ - authorizationMethod?: "header" | "body" | undefined; - } | undefined; } export interface OAuth2Namespace { From 94741db53706883754f9b8d4a9ecf396c622809c Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 25 Aug 2023 23:26:46 +0200 Subject: [PATCH 2/2] Use `import type` --- types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 7047fad..c9f229d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,6 +1,6 @@ -import { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'; -import { CookieSerializeOptions } from "@fastify/cookie"; -import { ModuleOptions } from 'simple-oauth2'; +import type { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'; +import type { CookieSerializeOptions } from "@fastify/cookie"; +import type { ModuleOptions } from 'simple-oauth2'; interface FastifyOauth2 extends FastifyPluginCallback { APPLE_CONFIGURATION: fastifyOauth2.ProviderConfiguration;