Skip to content

Commit 5ca5fd2

Browse files
committed
fix: Rename OAuth2SSOPlugin to OAuthPlugin and improve configuration handling
1 parent 51e73ed commit 5ca5fd2

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

index.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ import { IHttpServer } from "adminforth";
44
import { randomUUID } from 'crypto';
55
import type { OAuth2Adapter } from "adminforth";
66
import { AdminForthDataTypes } from "adminforth";
7+
import type { HttpExtra } from './types.js';
78

8-
interface OAuth2SSOPluginOptions {
9+
interface OAuthPluginOptions {
910
emailField: string;
1011
emailConfirmedField?: string;
1112
adapters: OAuth2Adapter[];
1213
}
1314

14-
export class OAuth2SSOPlugin extends AdminForthPlugin {
15-
private options: OAuth2SSOPluginOptions;
16-
private adminforth: IAdminForth;
15+
export class OAuthPlugin extends AdminForthPlugin {
16+
private options: OAuthPluginOptions;
17+
public adminforth: IAdminForth;
1718
private resource: AdminForthResource;
1819

19-
constructor(options: OAuth2SSOPluginOptions) {
20+
constructor(options: OAuthPluginOptions) {
2021
super(options, import.meta.url);
2122
if (!options.emailField) {
22-
throw new Error('OAuth2SSOPlugin: emailField is required');
23+
throw new Error('OAuthPlugin: emailField is required');
2324
}
2425
this.options = options;
2526
}
@@ -32,26 +33,26 @@ export class OAuth2SSOPlugin extends AdminForthPlugin {
3233

3334
// Validate emailField exists in resource
3435
if (!resource.columns.find(col => col.name === this.options.emailField)) {
35-
throw new Error(`OAuth2SSOPlugin: emailField "${this.options.emailField}" not found in resource columns`);
36+
throw new Error(`OAuthPlugin: emailField "${this.options.emailField}" not found in resource columns`);
3637
}
3738

3839
// Validate emailConfirmedField if provided
3940
if (this.options.emailConfirmedField) {
4041
const confirmedField = resource.columns.find(col => col.name === this.options.emailConfirmedField);
4142
if (!confirmedField) {
42-
throw new Error(`OAuth2SSOPlugin: emailConfirmedField "${this.options.emailConfirmedField}" not found in resource columns`);
43+
throw new Error(`OAuthPlugin: emailConfirmedField "${this.options.emailConfirmedField}" not found in resource columns`);
4344
}
4445
if (confirmedField.type !== AdminForthDataTypes.BOOLEAN) {
45-
throw new Error(`OAuth2SSOPlugin: emailConfirmedField "${this.options.emailConfirmedField}" must be a boolean field`);
46+
throw new Error(`OAuthPlugin: emailConfirmedField "${this.options.emailConfirmedField}" must be a boolean field`);
4647
}
4748
}
4849

4950
// Make sure customization and loginPageInjections exist
50-
if (!adminforth.config.customization) {
51-
adminforth.config.customization = {};
52-
}
53-
if (!adminforth.config.customization.loginPageInjections) {
54-
adminforth.config.customization.loginPageInjections = { underInputs: [] };
51+
if (!adminforth.config.customization?.loginPageInjections) {
52+
adminforth.config.customization = {
53+
...adminforth.config.customization,
54+
loginPageInjections: { underInputs: [] }
55+
};
5556
}
5657

5758
// Register the component with the correct plugin path

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{
22
"name": "@adminforth/oauth",
33
"version": "1.0.0",
4+
"type": "module",
45
"main": "dist/index.js",
56
"types": "dist/index.d.ts",
67
"scripts": {
8+
"build": "tsc && rsync -av --exclude 'node_modules' custom dist/",
79
"rollout": "tsc && rsync -av --exclude 'node_modules' custom dist/",
810
"prepare": "npm link adminforth"
911
},
1012
"repository": {
1113
"type": "git",
12-
"url": "https://github.com/devforth/adminforth-sso-auth"
14+
"url": "https://github.com/devforth/adminforth-oauth"
1315
},
14-
"keywords": ["adminforth", "sso", "auth", "oauth", "google auth", "github auth"],
16+
"keywords": ["adminforth", "oauth", "google auth", "github auth"],
1517
"author": "devforth",
1618
"license": "MIT",
1719
"description": "AdminForth OAuth Plugin",

types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@ export interface PluginOptions {
7474
error?: string;
7575
}>;
7676
}
77+
78+
export interface HttpExtra {
79+
headers: Record<string, string>;
80+
cookies: Record<string, string>;
81+
requestUrl: string;
82+
query: Record<string, any>;
83+
body: Record<string, any>;
84+
}

0 commit comments

Comments
 (0)