Skip to content

Commit

Permalink
fix: enable CORS on well-known routes (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmd5 authored Jan 10, 2025
1 parent 45f3e2d commit b22fb30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-emus-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openauthjs/openauth": patch
---

fix: enable CORS on well-known routes
60 changes: 39 additions & 21 deletions packages/openauth/src/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,28 +738,46 @@ export function issuer<
app.route(`/${name}`, route)
}

app.get("/.well-known/jwks.json", async (c) => {
const all = await allSigning
return c.json({
keys: all.map((item) => ({
...item.jwk,
exp: item.expired
? Math.floor(item.expired.getTime() / 1000)
: undefined,
})),
})
})
app.get(
"/.well-known/jwks.json",
cors({
origin: "*",
allowHeaders: ["*"],
allowMethods: ["GET"],
credentials: false,
}),
async (c) => {
const all = await allSigning
return c.json({
keys: all.map((item) => ({
...item.jwk,
exp: item.expired
? Math.floor(item.expired.getTime() / 1000)
: undefined,
})),
})
},
)

app.get("/.well-known/oauth-authorization-server", async (c) => {
const iss = issuer(c)
return c.json({
issuer: iss,
authorization_endpoint: `${iss}/authorize`,
token_endpoint: `${iss}/token`,
jwks_uri: `${iss}/.well-known/jwks.json`,
response_types_supported: ["code", "token"],
})
})
app.get(
"/.well-known/oauth-authorization-server",
cors({
origin: "*",
allowHeaders: ["*"],
allowMethods: ["GET"],
credentials: false,
}),
async (c) => {
const iss = issuer(c)
return c.json({
issuer: iss,
authorization_endpoint: `${iss}/authorize`,
token_endpoint: `${iss}/token`,
jwks_uri: `${iss}/.well-known/jwks.json`,
response_types_supported: ["code", "token"],
})
},
)

app.post(
"/token",
Expand Down

0 comments on commit b22fb30

Please sign in to comment.