Skip to content

Commit

Permalink
fix: add saml support in the adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
markusahlstrand committed Aug 16, 2024
1 parent f75adf8 commit 1fe78de
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 9 deletions.
6 changes: 6 additions & 0 deletions apps/demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @authhero/demo

## 0.0.8

### Patch Changes

- [email protected]

## 0.0.7

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@authhero/demo",
"private": true,
"version": "0.0.7",
"version": "0.0.8",
"scripts": {
"dev": "bun --watch src/bun.ts"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/adapter-interfaces/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @authhero/adapter-interfaces

## 0.11.0

### Minor Changes

- Add the addons property

### Patch Changes

- Update the applications schema to handle addOns

## 0.10.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-interfaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/markusahlstrand/authhero"
},
"version": "0.10.5",
"version": "0.11.0",
"files": [
"dist"
],
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-interfaces/src/adapters/Applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface CreateApplicationParams {
client_secret: string;
id: string;
disable_sign_ups: boolean;
addons?: Record<string, Record<string, string | number>>;
}

export interface ApplicationsAdapter {
Expand Down
43 changes: 41 additions & 2 deletions packages/adapter-interfaces/src/types/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@ import { z } from "@hono/zod-openapi";
export const applicationInsertSchema = z.object({
id: z.string(),
name: z.string(),
callbacks: z
.string()
.transform((val) => (val === null ? "" : val))
.default("")
.openapi({
description:
"Comma-separated list of URLs whitelisted to use as a callback to the client after authentication.",
}),
allowed_origins: z
.string()
.transform((val) => (val === null ? "" : val))
.default("")
.openapi({
description:
"Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level. Query strings and hash information are not taken into account when validating these URLs.",
}),
web_origins: z
.string()
.transform((val) => (val === null ? "" : val))
.default("")
.openapi({
description:
"Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.",
}),
addons: z
.record(z.string(), z.record(z.string(), z.union([z.string(), z.number()])))
.optional()
.openapi({
description:
"Addons associated with the client. The key is the addon's package name and the value is an object with the configuration for the addon.",
}),
// @deprecated. Renamed to match the auth0 API
allowed_web_origins: z
.string()
.transform((val) => (val === null ? "" : val))
Expand All @@ -17,9 +49,16 @@ export const applicationInsertSchema = z.object({
.default(""),
email_validation: z
.enum(["enabled", "disabled", "enforced"])
.default("enforced"),
.default("enforced")
.openapi({
description:
"Defines if it possible to sign in with an unverified email and if verification emails will be sent. This is not available in auth0",
}),
client_secret: z.string().default(""),
disable_sign_ups: z.boolean().default(false),
disable_sign_ups: z.boolean().default(false).openapi({
description:
"Prevents users from signing up using the hosted login page. This is not available in auth0",
}),
});
export type ApplicationInsert = z.infer<typeof applicationInsertSchema>;

Expand Down
1 change: 1 addition & 0 deletions packages/adapter-interfaces/src/types/AuthParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum AuthorizationResponseMode {
FRAGMENT = "fragment",
FORM_POST = "form_post",
WEB_MESSAGE = "web_message",
SAML_POST = "saml_post",
}

export enum CodeChallengeMethod {
Expand Down
8 changes: 8 additions & 0 deletions packages/authhero/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# authhero

## 0.2.10

### Patch Changes

- Updated dependencies
- Updated dependencies
- @authhero/adapter-interfaces@0.11.0

## 0.2.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/authhero/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "authhero",
"version": "0.2.9",
"version": "0.2.10",
"files": [
"dist"
],
Expand Down
8 changes: 8 additions & 0 deletions packages/drizzle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @authhero/drizzle

## 0.1.26

### Patch Changes

- Updated dependencies
- Updated dependencies
- @authhero/adapter-interfaces@0.11.0

## 0.1.25

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/markusahlstrand/authhero"
},
"version": "0.1.25",
"version": "0.1.26",
"files": [
"dist"
],
Expand Down
12 changes: 12 additions & 0 deletions packages/kysely/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @authhero/kysely-adapter

## 0.7.0

### Minor Changes

- Add the addons property

### Patch Changes

- Updated dependencies
- Updated dependencies
- @authhero/adapter-interfaces@0.11.0

## 0.6.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/kysely/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/markusahlstrand/authhero"
},
"version": "0.6.11",
"version": "0.7.0",
"files": [
"dist"
],
Expand Down
1 change: 1 addition & 0 deletions packages/kysely/src/applications/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function create(db: Kysely<Database>) {
updated_at: new Date().toISOString(),
...params,
disable_sign_ups: params.disable_sign_ups ? 1 : 0,
addons: params.addons ? JSON.stringify(params.addons) : null,
};

await db
Expand Down
3 changes: 3 additions & 0 deletions packages/kysely/src/applications/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export function get(db: Kysely<Database>) {
}

application.disable_sign_ups = !!application.disable_sign_ups;
application.addons = application.addons
? JSON.parse(application.addons)
: {};

return removeNullProperties(application);
};
Expand Down
7 changes: 6 additions & 1 deletion packages/kysely/src/applications/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export function list(db: Kysely<Database>) {
.selectFrom("applications")
.where("applications.tenant_id", "=", tenantId);

const applications: Application[] = await query.selectAll().execute();
const results = await query.selectAll().execute();
const applications: Application[] = results.map((result) => ({
...result,
disable_sign_ups: !!result.disable_sign_ups,
addons: result.addons ? JSON.parse(result.addons) : {},
}));

return {
applications,
Expand Down
10 changes: 9 additions & 1 deletion packages/kysely/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SqlAuthenticationCode } from "./authenticationCodes/AuthenticationCode"
import { SqlUser } from "./users/User";
import {
Application,
applicationSchema,
Certificate,
Code,
Connection,
Expand Down Expand Up @@ -32,8 +33,15 @@ const sqlLoginSchema = flattenSchema(loginSchema).extend({
});
type SqlLogin = z.infer<typeof sqlLoginSchema>;

const sqlApplicationSchema = z.object({
...applicationSchema.shape,
tenant_id: z.string(),
// The addons will be stored as JSON in a text column
addons: z.string().optional(),
});

export interface Database {
applications: Application & { tenant_id: string };
applications: z.infer<typeof sqlApplicationSchema>;
authentication_codes: SqlAuthenticationCode;
branding: SqlBranding;
codes: Code & { tenant_id: string };
Expand Down

0 comments on commit 1fe78de

Please sign in to comment.