Skip to content

Commit abf4754

Browse files
committed
# Conflicts: # src/runtime/server/lib/oauth/auth0.ts
2 parents 7113f98 + 36cadda commit abf4754

File tree

12 files changed

+206
-4
lines changed

12 files changed

+206
-4
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# Changelog
22

33

4+
## v0.0.9
5+
6+
[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.8...v0.0.9)
7+
8+
### 🚀 Enhancements
9+
10+
- Add max_age param for auth0 ([#26](https://github.com/Atinux/nuxt-auth-utils/pull/26))
11+
- Added Microsoft as oauth provider ([#8](https://github.com/Atinux/nuxt-auth-utils/pull/8))
12+
13+
### ❤️ Contributors
14+
15+
- Jakub Frelik <j.frelik.it@outlook.com>
16+
- Uģis ([@BerzinsU](http://github.com/BerzinsU))
17+
418
## v0.0.8
519

620
[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.7...v0.0.8)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ It can also be set using environment variables:
150150
#### Supported OAuth Providers
151151

152152
- Auth0
153+
- Battle.net
153154
- Discord
154155
- GitHub
155156
- Google
157+
- Microsoft
156158
- Spotify
157159
- Twitch
158-
- Battle.net
159160

160161
You can add your favorite provider by creating a new file in [src/runtime/server/lib/oauth/](./src/runtime/server/lib/oauth/).
161162

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuxt-auth-utils",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Minimalist Auth module for Nuxt with SSR",
55
"repository": "Atinux/nuxt-auth-utils",
66
"license": "MIT",

playground/.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ NUXT_OAUTH_TWITCH_CLIENT_SECRET=
1515
NUXT_OAUTH_AUTH0_CLIENT_ID=
1616
NUXT_OAUTH_AUTH0_CLIENT_SECRET=
1717
NUXT_OAUTH_AUTH0_DOMAIN=
18+
# Microsoft OAuth
19+
NUXT_OAUTH_MICROSOFT_CLIENT_ID=
20+
NUXT_OAUTH_MICROSOFT_CLIENT_SECRET=
21+
NUXT_OAUTH_MICROSOFT_TENANT=
1822
# Discord
1923
NUXT_OAUTH_DISCORD_CLIENT_ID=
2024
NUXT_OAUTH_DISCORD_CLIENT_SECRET=
2125
# Battle.net OAuth
2226
NUXT_OAUTH_BATTLEDOTNET_CLIENT_ID=
23-
NUXT_OAUTH_BATTLEDOTNET_CLIENT_SECRET=
27+
NUXT_OAUTH_BATTLEDOTNET_CLIENT_SECRET=

playground/app.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ const providers = computed(() => [
4444
disabled: Boolean(user.value?.battledotnet),
4545
icon: 'i-simple-icons-battledotnet',
4646
},
47+
{
48+
label: user.value?.microsoft?.displayName || 'Microsoft',
49+
to: '/auth/microsoft',
50+
disabled: Boolean(user.value?.microsoft),
51+
icon: 'i-simple-icons-microsoft',
52+
}
53+
4754
].map(p => ({
4855
...p,
4956
prefetch: false,

playground/auth.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ declare module '#auth-utils' {
66
google?: any
77
twitch?: any
88
auth0?: any
9+
microsoft?: any;
910
discord?: any
1011
battledotnet?: any
1112
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default oauth.microsoftEventHandler({
2+
async onSuccess(event, { user }) {
3+
await setUserSession(event, {
4+
user: {
5+
microsoft: user,
6+
},
7+
loggedInAt: Date.now()
8+
})
9+
10+
return sendRedirect(event, '/')
11+
}
12+
})
13+

src/module.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ export default defineNuxtModule<ModuleOptions>({
9898
clientSecret: '',
9999
domain: ''
100100
})
101+
// Microsoft OAuth
102+
runtimeConfig.oauth.microsoft = defu(runtimeConfig.oauth.microsoft, {
103+
clientId: '',
104+
clientSecret: '',
105+
tenant: '',
106+
scope: [],
107+
authorizationURL: '',
108+
tokenURL: '',
109+
userURL: ''
110+
})
101111
// Discord OAuth
102112
runtimeConfig.oauth.discord = defu(runtimeConfig.oauth.discord, {
103113
clientId: '',

src/runtime/server/lib/oauth/auth0.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export interface OAuthAuth0Config {
4141
*/
4242
emailRequired?: boolean
4343
/**
44+
* Maximum Authentication Age. If the elapsed time is greater than this value, the OP must attempt to actively re-authenticate the end-user.
45+
* @default 0
46+
* @see https://auth0.com/docs/authenticate/login/max-age-reauthentication
47+
*/
48+
maxAge?: number
49+
/**
4450
* checks
4551
* @default []
4652
* @see https://auth0.com/docs/flows/authorization-code-flow-with-proof-key-for-code-exchange-pkce
@@ -82,6 +88,7 @@ export function auth0EventHandler({ config, onSuccess, onError }: OAuthConfig<OA
8288
redirect_uri: redirectUrl,
8389
scope: config.scope.join(' '),
8490
audience: config.audience || '',
91+
max_age: config.maxAge || 0,
8592
...authParam
8693
})
8794
)

src/runtime/server/lib/oauth/discord.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export function discordEventHandler({ config, onSuccess, onError }: OAuthConfig<
109109
return { error }
110110
})
111111
if (tokens.error) {
112-
console.log(tokens)
113112
const error = createError({
114113
statusCode: 401,
115114
message: `Discord login failed: ${tokens.error?.data?.error_description || 'Unknown error'}`,

0 commit comments

Comments
 (0)