Skip to content

Commit 6b50ea1

Browse files
larsrickertautofix-ci[bot]atinux
authored
feat: add OpenID Connect (OIDC) provider (#444)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Sébastien Chopin <atinux@gmail.com>
1 parent df5c66e commit 6b50ea1

8 files changed

Lines changed: 390 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ It can also be set using environment variables:
236236
- LinkedIn
237237
- LiveChat
238238
- Microsoft
239+
- OIDC / OpenID Connect (Generic)
239240
- Okta
240241
- Ory
241242
- PayPal
@@ -420,7 +421,7 @@ export default defineWebAuthnRegisterEventHandler({
420421
// If he registers a new account with credentials
421422
return z.object({
422423
// we want the userName to be a valid email
423-
userName: z.string().email()
424+
userName: z.string().email()
424425
}).parse(userBody)
425426
},
426427
async onSuccess(event, { credential, user }) {

playground/app/pages/index.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ const providers = computed(() =>
281281
disabled: Boolean(user.value?.shopifyCustomer),
282282
icon: 'i-simple-icons-shopify',
283283
},
284+
{
285+
title: user.value?.oidc || 'OIDC',
286+
to: '/auth/oidc',
287+
disabled: Boolean(user.value?.oidc),
288+
icon: 'i-simple-icons-openid',
289+
},
284290
].map(p => ({
285291
...p,
286292
prefetch: false,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default defineOAuthOidcEventHandler({
2+
config: {
3+
scope: ['openid', 'profile', 'email'],
4+
},
5+
async onSuccess(event, { user }) {
6+
await setUserSession(event, {
7+
user: {
8+
oidc: user.name,
9+
},
10+
loggedInAt: Date.now(),
11+
})
12+
13+
return sendRedirect(event, '/')
14+
},
15+
})

playground/shared/types/auth.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ declare module '#auth-utils' {
4747
roblox?: string
4848
okta?: string
4949
ory?: string
50+
oidc?: string
5051
}
5152

5253
interface UserSession {

src/module.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { writeFile, readFile } from 'node:fs/promises'
1+
import type { ScryptConfig } from '@adonisjs/hash/types'
22
import {
3-
defineNuxtModule,
4-
addPlugin,
5-
createResolver,
3+
addComponentsDir,
64
addImports,
5+
addPlugin,
76
addServerHandler,
8-
addServerPlugin,
97
addServerImportsDir,
10-
addComponentsDir,
8+
addServerPlugin,
9+
createResolver,
10+
defineNuxtModule,
1111
logger,
1212
} from '@nuxt/kit'
13-
import { join } from 'pathe'
1413
import { defu } from 'defu'
15-
import { randomUUID } from 'uncrypto'
16-
import type { ScryptConfig } from '@adonisjs/hash/types'
1714
import type { SessionConfig } from 'h3'
18-
import { atprotoProviderDefaultClientMetadata, atprotoProviders, getClientMetadataFilename } from './runtime/utils/atproto'
15+
import { readFile, writeFile } from 'node:fs/promises'
16+
import { join } from 'pathe'
17+
import { randomUUID } from 'uncrypto'
1918
import type { AtprotoProviderClientMetadata } from './runtime/types/atproto'
19+
import { atprotoProviderDefaultClientMetadata, atprotoProviders, getClientMetadataFilename } from './runtime/utils/atproto'
2020

2121
// Module options TypeScript interface definition
2222
export interface ModuleOptions {
@@ -530,5 +530,13 @@ export default defineNuxtModule<ModuleOptions>({
530530
redirectURL: '',
531531
scope: [],
532532
})
533+
// OIDC OAuth
534+
runtimeConfig.oauth.oidc = defu(runtimeConfig.oauth.oidc, {
535+
clientId: '',
536+
clientSecret: '',
537+
openidConfig: '',
538+
redirectURL: '',
539+
scope: [],
540+
})
533541
},
534542
})

0 commit comments

Comments
 (0)