Skip to content

Commit

Permalink
Merge branch 'main' into oidc
Browse files Browse the repository at this point in the history
* main:
  chore(release): v0.0.15
  chore: up deps
  feat: added aws cognito provider (atinux#36)
  feat: add auth0 connection parameter to config (atinux#39)
  fix: replace encoded space characters with regular spaces (atinux#40)
  chore(release): v0.0.14
  chore: update deps
  feat: added keycloak as oauth provider (atinux#23)
  chore: test bundler module resolution (atinux#32)
  chore(release): v0.0.13
  chore: rename session from verify to fetch
  chore(release): v0.0.12
  fix: correct arguments for hooks
  chore(release): v0.0.11
  feat: add sessionHooks to extend user sessions
  • Loading branch information
maximilianmikus committed Jan 31, 2024
2 parents d85568e + ec128cc commit ed1ffb5
Show file tree
Hide file tree
Showing 23 changed files with 2,419 additions and 771 deletions.
2 changes: 2 additions & 0 deletions .nuxtrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# enable TypeScript bundler module resolution - https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler
experimental.typescriptBundlerResolution=true
79 changes: 79 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,85 @@
# Changelog


## v0.0.15

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.14...v0.0.15)

### 🚀 Enhancements

- Add auth0 connection parameter to config ([#39](https://github.com/Atinux/nuxt-auth-utils/pull/39))
- Added aws cognito provider ([#36](https://github.com/Atinux/nuxt-auth-utils/pull/36))

### 🩹 Fixes

- Replace encoded space characters with regular spaces ([#40](https://github.com/Atinux/nuxt-auth-utils/pull/40))

### 🏡 Chore

- Up deps ([a7bd06b](https://github.com/Atinux/nuxt-auth-utils/commit/a7bd06b))

### ❤️ Contributors

- Sébastien Chopin ([@Atinux](http://github.com/Atinux))
- Dvir Hazout <[email protected]>
- Silvio Eckl <[email protected]>
- Ahmed Rangel ([@ahmedrangel](http://github.com/ahmedrangel))

## v0.0.14

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.13...v0.0.14)

### 🚀 Enhancements

- Added keycloak as oauth provider ([#23](https://github.com/Atinux/nuxt-auth-utils/pull/23))

### 🏡 Chore

- Test bundler module resolution ([#32](https://github.com/Atinux/nuxt-auth-utils/pull/32))
- Update deps ([9d6b258](https://github.com/Atinux/nuxt-auth-utils/commit/9d6b258))

### ❤️ Contributors

- Sébastien Chopin ([@Atinux](http://github.com/Atinux))
- Yue JIN
- Daniel Roe <[email protected]>

## v0.0.13

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.12...v0.0.13)

### 🏡 Chore

- Rename session from verify to fetch ([10694e9](https://github.com/Atinux/nuxt-auth-utils/commit/10694e9))

### ❤️ Contributors

- Sébastien Chopin ([@Atinux](http://github.com/Atinux))

## v0.0.12

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.11...v0.0.12)

### 🩹 Fixes

- Correct arguments for hooks ([6e0193e](https://github.com/Atinux/nuxt-auth-utils/commit/6e0193e))

### ❤️ Contributors

- Sébastien Chopin ([@Atinux](http://github.com/Atinux))

## v0.0.11

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.10...v0.0.11)

### 🚀 Enhancements

- Add sessionHooks to extend user sessions ([c470319](https://github.com/Atinux/nuxt-auth-utils/commit/c470319))

### ❤️ Contributors

- Sébastien Chopin ([@Atinux](http://github.com/Atinux))

## v0.0.10

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.9...v0.0.10)
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ It can also be set using environment variables:
#### Supported OAuth Providers

- Auth0
- AWS Cognito
- Battle.net
- Discord
- GitHub
- Google
- Keycloak
- LinkedIn
- Microsoft
- Spotify
Expand Down Expand Up @@ -189,6 +191,28 @@ export default oauth.githubEventHandler({

Make sure to set the callback URL in your OAuth app settings as `<your-domain>/auth/github`.

### Extend Session

We leverage hooks to let you extend the session data with your own data or to log when the user clear its session.

```ts
// server/plugins/session.ts
export default defineNitroPlugin(() => {
// Called when the session is fetched during SSR for the Vue composable (/api/_auth/session)
// Or when we call useUserSession().fetch()
sessionHooks.hook('fetch', async (session, event) => {
// extend User Session by calling your database
// or
// throw createError({ ... }) if session is invalid for example
})

// Called when we call useServerSession().clear() or clearUserSession(event)
sessionHooks.hook('clear', async (session, event) => {
// Log that user logged out
})
})
```

## Development

```bash
Expand Down
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-auth-utils",
"version": "0.0.10",
"version": "0.0.15",
"description": "Minimalist Auth module for Nuxt with SSR",
"repository": "Atinux/nuxt-auth-utils",
"license": "MIT",
Expand Down Expand Up @@ -30,26 +30,27 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@nuxt/kit": "^3.8.2",
"defu": "^6.1.3",
"@nuxt/kit": "^3.9.3",
"defu": "^6.1.4",
"hookable": "^5.5.3",
"ofetch": "^1.3.3",
"ohash": "^1.1.3"
},
"devDependencies": {
"@iconify-json/simple-icons": "^1.1.82",
"@iconify-json/simple-icons": "^1.1.90",
"@nuxt/devtools": "latest",
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/module-builder": "^0.5.4",
"@nuxt/schema": "^3.8.2",
"@nuxt/test-utils": "^3.8.1",
"@nuxt/ui": "^2.11.0",
"@nuxt/ui-pro": "^0.5.0",
"@types/node": "^20.10.4",
"@nuxt/module-builder": "^0.5.5",
"@nuxt/schema": "^3.9.3",
"@nuxt/test-utils": "^3.11.0",
"@nuxt/ui": "^2.12.3",
"@nuxt/ui-pro": "^0.7.3",
"@types/node": "^20.11.10",
"changelogen": "^0.5.5",
"eslint": "^8.55.0",
"nuxt": "^3.8.2",
"eslint": "^8.56.0",
"nuxt": "^3.9.3",
"typescript": "^5.3.3",
"vitest": "^1.0.2",
"vue-tsc": "^1.8.25"
"vitest": "^1.2.2",
"vue-tsc": "^1.8.27"
}
}
10 changes: 10 additions & 0 deletions playground/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ NUXT_OAUTH_DISCORD_CLIENT_SECRET=
# Battle.net OAuth
NUXT_OAUTH_BATTLEDOTNET_CLIENT_ID=
NUXT_OAUTH_BATTLEDOTNET_CLIENT_SECRET=
# Keycloak OAuth
NUXT_OAUTH_KEYCLOAK_CLIENT_ID=
NUXT_OAUTH_KEYCLOAK_CLIENT_SECRET=
NUXT_OAUTH_KEYCLOAK_SERVER_URL=
NUXT_OAUTH_KEYCLOAK_REALM=
# LinkedIn
NUXT_OAUTH_LINKEDIN_CLIENT_ID=
NUXT_OAUTH_LINKEDIN_CLIENT_SECRET=
# Cognito
NUXT_OAUTH_COGNITO_USER_POOL_ID=
NUXT_OAUTH_COGNITO_CLIENT_ID=
NUXT_OAUTH_COGNITO_CLIENT_SECRET=
NUXT_OAUTH_COGNITO_REGION=
13 changes: 12 additions & 1 deletion playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,24 @@ const providers = computed(() => [
disabled: Boolean(user.value?.microsoft),
icon: 'i-simple-icons-microsoft',
},
{
label: user.value?.keycloak?.preferred_username || 'Keycloak',
to: '/auth/keycloak',
disabled: Boolean(user.value?.keycloak),
icon: 'i-simple-icons-redhat'
},
{
label: user.value?.linkedin?.email || 'LinkedIn',
to: '/auth/linkedin',
disabled: Boolean(user.value?.linkedin),
icon: 'i-simple-icons-linkedin',
},
{
label: user.value?.cognito?.email || 'Cognito',
to: '/auth/cognito',
disabled: Boolean(user.value?.cognito),
icon: 'i-simple-icons-amazonaws',
}
].map(p => ({
...p,
prefetch: false,
Expand Down
2 changes: 2 additions & 0 deletions playground/auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ declare module '#auth-utils' {
microsoft?: any;
discord?: any
battledotnet?: any
keycloak?: any
linkedin?: any
}
extended?: any
loggedInAt: number
}
}
Expand Down
4 changes: 2 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"generate": "nuxi generate"
},
"dependencies": {
"nuxt": "3.8.1",
"nuxt": "^3.9.3",
"nuxt-auth-utils": "latest",
"vue": "3.3.8"
"vue": "^3.4.15"
}
}
15 changes: 15 additions & 0 deletions playground/server/plugins/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default defineNitroPlugin(() => {
sessionHooks.hook('fetch', async (session) => {
// Extend User Session
// Or throw createError({ ... }) if session is invalid
session.extended = {
fromHooks: true
}
})

sessionHooks.hook('clear', async (session) => {
// Log that user logged out
console.log('User logged out')
})
})

12 changes: 12 additions & 0 deletions playground/server/routes/auth/cognito.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default oauth.cognitoEventHandler({
async onSuccess(event, { user }) {
await setUserSession(event, {
user: {
cognito: user,
},
loggedInAt: Date.now()
})

return sendRedirect(event, '/')
}
})
12 changes: 12 additions & 0 deletions playground/server/routes/auth/keycloak.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default oauth.keycloakEventHandler({
async onSuccess(event, { user }) {
await setUserSession(event, {
user: {
keycloak: user,
},
loggedInAt: Date.now(),
})

return sendRedirect(event, '/')
},
})
Loading

0 comments on commit ed1ffb5

Please sign in to comment.