Skip to content

Commit f9a5929

Browse files
committed
feat(oidc-auth): support empty OIDC client secret
1 parent 6c36f52 commit f9a5929

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

.changeset/every-pugs-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hono/oidc-auth': major
3+
---
4+
5+
Support empty OIDC_CLIENT_SECRET

packages/oidc-auth/src/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const setOidcAuthEnv = (c: Context, config?: Partial<OidcAuthEnv>) => {
113113
if (oidcAuthEnv.OIDC_CLIENT_SECRET === undefined) {
114114
throw new HTTPException(500, { message: 'OIDC client secret is not provided' })
115115
}
116+
// Allow empty string as valid client secret
116117
oidcAuthEnv.OIDC_REDIRECT_URI = oidcAuthEnv.OIDC_REDIRECT_URI ?? defaultOidcRedirectUri
117118
if (!oidcAuthEnv.OIDC_REDIRECT_URI.startsWith('/')) {
118119
try {
@@ -167,11 +168,18 @@ export const getClient = (c: Context): oauth2.Client => {
167168
const env = getOidcAuthEnv(c)
168169
let client = c.get('oidcClient')
169170
if (client === undefined) {
170-
client = {
171-
client_id: env.OIDC_CLIENT_ID,
172-
client_secret: env.OIDC_CLIENT_SECRET,
173-
token_endpoint_auth_method: 'client_secret_basic',
174-
}
171+
client =
172+
env.OIDC_CLIENT_SECRET === ''
173+
? {
174+
// No client secret provided, use 'none' auth method
175+
client_id: env.OIDC_CLIENT_ID,
176+
token_endpoint_auth_method: 'none',
177+
}
178+
: {
179+
client_id: env.OIDC_CLIENT_ID,
180+
client_secret: env.OIDC_CLIENT_SECRET,
181+
token_endpoint_auth_method: 'client_secret_basic',
182+
}
175183
c.set('oidcClient', client)
176184
}
177185
return client

0 commit comments

Comments
 (0)