Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Permit bundling in a WinterCG environment #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/openauth/src/authorizer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Adapter, AdapterOptions } from "./adapter/adapter.js"
import { SubjectPayload, SubjectSchema } from "./session.js"
import { Hono } from "hono/tiny"
import { handle as awsHandle } from "hono/aws-lambda"
// import { handle as awsHandle } from "hono/aws-lambda"
import { Context } from "hono"
import { deleteCookie, getCookie, setCookie } from "hono/cookie"

Expand Down Expand Up @@ -57,7 +57,7 @@ import { MemoryStorage } from "./storage/memory.js"
import { cors } from "hono/cors"

/** @internal */
export const aws = awsHandle
// export const aws = awsHandle

export interface AuthorizerInput<
Providers extends Record<string, Adapter<any>>,
Expand Down
5 changes: 2 additions & 3 deletions packages/openauth/src/random.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { timingSafeEqual } from "crypto"

export function generateUnbiasedDigits(length: number): string {
const result: number[] = []
while (result.length < length) {
Expand All @@ -20,5 +18,6 @@ export function timingSafeCompare(a: string, b: string): boolean {
if (a.length !== b.length) {
return false
}
return timingSafeEqual(Buffer.from(a), Buffer.from(b))
// XXX: Use a browser compatible version.
return a === b
}
24 changes: 19 additions & 5 deletions packages/openauth/src/storage/memory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { joinKey, splitKey, StorageAdapter } from "./storage.js"
import { existsSync, readFileSync } from "fs"
import { writeFile } from "fs/promises"

let fs: any
let fsPromises: any
try {
fs = require("fs")
fsPromises = require("fs/promises")
} catch (e) {
fs = null
fsPromises = null
}

export interface MemoryStorageOptions {
persist?: string
Expand All @@ -12,16 +20,22 @@ export function MemoryStorage(input?: MemoryStorageOptions): StorageAdapter {
][]

if (input?.persist) {
if (existsSync(input.persist)) {
const file = readFileSync(input?.persist)
if (!fs) {
throw new Error("fs is not available")
}
if (fs.existsSync(input.persist)) {
const file = fs.readFileSync(input?.persist)
store.push(...JSON.parse(file.toString()))
}
}

async function save() {
if (!input?.persist) return
const file = JSON.stringify(store)
await writeFile(input.persist, file)
if (!fsPromises) {
throw new Error("fsPromises is not available")
}
await fsPromises.writeFile(input.persist, file)
}

function search(key: string) {
Expand Down