Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-server-side-session-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-hofmann authored Feb 5, 2025
2 parents d59daf5 + ed221c1 commit bcbcd84
Show file tree
Hide file tree
Showing 27 changed files with 4,031 additions and 1,240 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- run: corepack enable
- run: npm i -g --force corepack && corepack enable
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: 20
Expand Down
63 changes: 63 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,69 @@
# Changelog


## v0.5.13

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.12...v0.5.13)

### 🩹 Fixes

- **bluesky:** Use local map for session storing ([#340](https://github.com/atinux/nuxt-auth-utils/pull/340))

### 🏡 Chore

- **playground:** Update nuxt version ([4852cd7](https://github.com/atinux/nuxt-auth-utils/commit/4852cd7))
- Fix types ([43d7d11](https://github.com/atinux/nuxt-auth-utils/commit/43d7d11))

### ❤️ Contributors

- Neil Richter ([@noook](http://github.com/noook))
- Sébastien Chopin <[email protected]>

## v0.5.12

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.11...v0.5.12)

### 🚀 Enhancements

- **session:** Add generated session id ([#338](https://github.com/atinux/nuxt-auth-utils/pull/338))
- Add bluesky as a provider ([#281](https://github.com/atinux/nuxt-auth-utils/pull/281))

### 🏡 Chore

- Update deps ([1d4c52c](https://github.com/atinux/nuxt-auth-utils/commit/1d4c52c))

### ❤️ Contributors

- Sébastien Chopin <[email protected]>
- Neil Richter <[email protected]>

## v0.5.11

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.10...v0.5.11)

### 🚀 Enhancements

- Set `email_verified` in `user` on GitHub provider ([#332](https://github.com/atinux/nuxt-auth-utils/pull/332))
- **composable:** Add `openInPopup(route, { width, height })` ([#336](https://github.com/atinux/nuxt-auth-utils/pull/336))
- Add Gitea Oauth Provider ([#335](https://github.com/atinux/nuxt-auth-utils/pull/335))

### 🩹 Fixes

- Dammit corepack ([239f97a](https://github.com/atinux/nuxt-auth-utils/commit/239f97a))
- **microsoft:** Fix duplicated scopes ([#331](https://github.com/atinux/nuxt-auth-utils/pull/331))

### 🏡 Chore

- **release:** V0.5.10 ([42a2a7a](https://github.com/atinux/nuxt-auth-utils/commit/42a2a7a))
- **ci:** Fix corepack ([be2ccaf](https://github.com/atinux/nuxt-auth-utils/commit/be2ccaf))

### ❤️ Contributors

- H+ ([@justserdar](http://github.com/justserdar))
- Emmanuel Salomon ([@ManUtopiK](http://github.com/ManUtopiK))
- Sébastien Chopin ([@atinux](http://github.com/atinux))
- Alessandro Jean ([@alessandrojean](http://github.com/alessandrojean))

## v0.5.10

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.9...v0.5.10)
Expand Down
48 changes: 39 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Nuxt Auth Utils automatically adds some plugins to fetch the current user sessio

```vue
<script setup>
const { loggedIn, user, session, fetch, clear } = useUserSession()
const { loggedIn, user, session, fetch, clear, openInPopup } = useUserSession()
</script>
<template>
Expand All @@ -74,6 +74,8 @@ const { loggedIn, user, session, fetch, clear } = useUserSession()
<div v-else>
<h1>Not logged in</h1>
<a href="/auth/github">Login with GitHub</a>
<!-- or open the OAuth route in a popup -->
<button @click="openInPopup('/auth/github')">Login with GitHub</button>
</div>
</template>
```
Expand Down Expand Up @@ -106,6 +108,10 @@ interface UserSessionComposable {
* Clear the user session and remove the session cookie.
*/
clear: () => Promise<void>
/**
* Open the OAuth route in a popup that auto-closes when successful.
*/
openInPopup: (route: string, size?: { width?: number, height?: number }) => void
}
```

Expand Down Expand Up @@ -211,11 +217,13 @@ It can also be set using environment variables:
- Authentik
- AWS Cognito
- Battle.net
- Bluesky (AT Protocol)
- Discord
- Dropbox
- Facebook
- GitHub
- GitLab
- Gitea
- Google
- Hubspot
- Instagram
Expand Down Expand Up @@ -297,6 +305,28 @@ export default defineNuxtConfig({
})
```

### AT Protocol

Social networks that rely on AT Protocol (e.g., Bluesky) slightly differ from a regular OAuth flow.

To enable OAuth with AT Protocol, you need to:

1. Install the peer dependencies:

```bash
npx nypm i @atproto/oauth-client-node @atproto/api
```

2. Enable it in your `nuxt.config.ts`

```ts
export default defineNuxtConfig({
auth: {
atproto: true
}
})
```

### WebAuthn (passkey)

WebAuthn (Web Authentication) is a web standard that enhances security by replacing passwords with passkeys using public key cryptography. Users can authenticate with biometric data (like fingerprints or facial recognition) or physical devices (like USB keys), reducing the risk of phishing and password breaches. This approach offers a more secure and user-friendly authentication method, supported by major browsers and platforms.
Expand Down Expand Up @@ -836,26 +866,26 @@ This will automatically clean up any expired sessions based on your `sessionInac

```bash
# Install dependencies
npm install
pnpm install

# Generate type stubs
npm run dev:prepare
pnpm run dev:prepare

# Develop with the playground
npm run dev
pnpm run dev

# Build the playground
npm run dev:build
pnpm run dev:build

# Run ESLint
npm run lint
pnpm run lint

# Run Vitest
npm run test
npm run test:watch
pnpm run test
pnpm run test:watch

# Release new version
npm run release
pnpm run release
```

<!-- Badges -->
Expand Down
26 changes: 17 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-auth-utils",
"version": "0.5.10",
"version": "0.5.13",
"description": "Add Authentication to Nuxt applications with secured & sealed cookies sessions.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@adonisjs/hash": "^9.0.5",
"@nuxt/kit": "^3.15.2",
"@nuxt/kit": "^3.15.4",
"defu": "^6.1.4",
"h3": "^1.14.0",
"hookable": "^5.5.3",
Expand All @@ -49,6 +49,8 @@
"uncrypto": "^0.1.3"
},
"peerDependencies": {
"@atproto/api": "^0.13.15",
"@atproto/oauth-client-node": "^0.2.0",
"@simplewebauthn/browser": "^11.0.0",
"@simplewebauthn/server": "^11.0.0"
},
Expand All @@ -58,23 +60,29 @@
},
"@simplewebauthn/server": {
"optional": true
},
"@atproto/oauth-client-node": {
"optional": true
},
"@atproto/api": {
"optional": true
}
},
"devDependencies": {
"@iconify-json/simple-icons": "^1.2.21",
"@nuxt/devtools": "latest",
"@nuxt/eslint-config": "^0.7.5",
"@iconify-json/simple-icons": "^1.2.23",
"@nuxt/devtools": "2.0.0-beta.7",
"@nuxt/eslint-config": "^0.7.6",
"@nuxt/module-builder": "^0.8.4",
"@nuxt/schema": "^3.15.2",
"@nuxt/schema": "^3.15.4",
"@nuxt/test-utils": "^3.15.4",
"@nuxt/ui": "^2.21.0",
"@nuxt/ui-pro": "^1.7.0",
"@simplewebauthn/types": "^12.0.0",
"changelogen": "^0.5.7",
"eslint": "^9.18.0",
"nuxt": "^3.15.2",
"eslint": "^9.19.0",
"nuxt": "^3.15.4",
"typescript": "5.6.3",
"vitest": "^3.0.3",
"vitest": "^3.0.5",
"vue-tsc": "^2.2.0"
}
}
3 changes: 3 additions & 0 deletions playground/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ NUXT_OAUTH_GITHUB_CLIENT_SECRET=
# GitLab OAuth
NUXT_OAUTH_GITLAB_CLIENT_ID=
NUXT_OAUTH_GITLAB_CLIENT_SECRET=
# Gitea OAuth
NUXT_OAUTH_GITEA_CLIENT_ID=
NUXT_OAUTH_GITEA_CLIENT_SECRET=
# Spotify OAuth
NUXT_OAUTH_SPOTIFY_CLIENT_ID=
NUXT_OAUTH_SPOTIFY_CLIENT_SECRET=
Expand Down
29 changes: 28 additions & 1 deletion playground/app.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
const { user } = useUserSession()
const { user, openInPopup } = useUserSession()
const inPopup = ref(false)
const providers = computed(() =>
[
{
Expand All @@ -27,6 +28,22 @@ const providers = computed(() =>
disabled: Boolean(user.value?.github),
icon: 'i-simple-icons-github',
},
{
label: user.value?.bluesky || 'Bluesky',
click() {
const handle = prompt('Enter your Bluesky handle')
if (handle) {
navigateTo({
path: '/auth/bluesky',
query: { handle },
}, {
external: true,
})
}
},
disabled: Boolean(user.value?.bluesky),
icon: 'i-simple-icons-bluesky',
},
{
label: user.value?.gitlab || 'GitLab',
to: '/auth/gitlab',
Expand Down Expand Up @@ -205,6 +222,8 @@ const providers = computed(() =>
...p,
prefetch: false,
external: true,
to: inPopup.value ? '#' : p.to,
click: inPopup.value ? () => openInPopup(p.to) : p.click,
})),
)
</script>
Expand Down Expand Up @@ -259,6 +278,14 @@ const providers = computed(() =>
</UHeader>
<UMain>
<UContainer>
<div class="text-xs mt-4">
Popup mode <UToggle
v-model="inPopup"
size="xs"
name="open-in-popup"
label="Open in popup"
/>
</div>
<NuxtPage />
</UContainer>
</UMain>
Expand Down
2 changes: 2 additions & 0 deletions playground/auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
declare module '#auth-utils' {
interface User {
bluesky?: string
webauthn?: string
email?: string
password?: string
spotify?: string
gitea?: string
github?: string
gitlab?: string
google?: string
Expand Down
1 change: 1 addition & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default defineNuxtConfig({
// storageType: 'cache',
// sessionInactivityMaxAge: 60 * 2, // 2 minutes
// autoExtendSession: true,
atproto: true,
},
// runtimeConfig: {
// session: {
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@tsndr/cloudflare-worker-jwt": "^3.1.3",
"@vueuse/core": "^12.5.0",
"@vueuse/nuxt": "^12.5.0",
"nuxt": "^3.15.2",
"nuxt": "^3.15.4",
"nuxt-auth-utils": "latest",
"zod": "^3.24.1"
},
Expand Down
12 changes: 12 additions & 0 deletions playground/server/routes/auth/bluesky.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default defineOAuthBlueskyEventHandler({
async onSuccess(event, { user }) {
await setUserSession(event, {
user: {
bluesky: user.did,
},
loggedInAt: Date.now(),
})

return sendRedirect(event, '/')
},
})
15 changes: 15 additions & 0 deletions playground/server/routes/auth/gitea.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default defineOAuthGiteaEventHandler({
config: {
emailRequired: true,
},
async onSuccess(event, { user }) {
await setUserSession(event, {
user: {
gitea: user.email,
},
loggedInAt: Date.now(),
})
return sendRedirect(event, '/')
},

})
Loading

0 comments on commit bcbcd84

Please sign in to comment.