Skip to content

Commit c6198b8

Browse files
mariosantatinuxautofix-ci[bot]
authored
fix(LiveChat): Remove scope assumption with LiveChat login (#432)
Co-authored-by: Sébastien Chopin <seb@nuxt.com> Co-authored-by: Sébastien Chopin <atinux@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 84f879e commit c6198b8

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

playground/app/pages/index.vue

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ const providers = computed(() =>
3333
onClick() {
3434
const handle = prompt('Enter your Bluesky handle')
3535
if (handle) {
36-
navigateTo({
37-
path: '/auth/bluesky',
38-
query: { handle },
39-
}, {
40-
external: true,
41-
})
36+
navigateTo(
37+
{
38+
path: '/auth/bluesky',
39+
query: { handle },
40+
},
41+
{
42+
external: true,
43+
},
44+
)
4245
}
4346
},
4447
disabled: Boolean(user.value?.bluesky),
@@ -248,6 +251,12 @@ const providers = computed(() =>
248251
disabled: Boolean(user.value?.heroku),
249252
icon: 'i-simple-icons-heroku',
250253
},
254+
{
255+
title: user.value?.livechat || 'Livechat',
256+
to: '/auth/livechat',
257+
disabled: Boolean(user.value?.livechat),
258+
icon: 'i-simple-icons-livechat',
259+
},
251260
{
252261
title: user.value?.roblox || 'Roblox',
253262
to: '/auth/roblox',
@@ -283,7 +292,9 @@ const providers = computed(() =>
283292
<AuthState>
284293
<template #default="{ session }">
285294
<strong>User session:</strong>
286-
<pre class="border border-default p-2 bg-muted rounded-md">{{ session || 'null' }}</pre>
295+
<pre class="border border-default p-2 bg-muted rounded-md">{{
296+
session || "null"
297+
}}</pre>
287298
</template>
288299
<template #placeholder>
289300
...
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
export default defineOAuthLiveChatEventHandler({
2-
config: {},
32
async onSuccess(event, { user }) {
43
await setUserSession(event, {
54
user: {
6-
livechat: user,
5+
livechat: user.name,
76
},
87
loggedInAt: Date.now(),
98
})
109

1110
return sendRedirect(event, '/')
1211
},
13-
async onError() {},
1412
})

playground/shared/types/auth.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ declare module '#auth-utils' {
4343
salesforce?: string
4444
slack?: string
4545
heroku?: string
46+
livechat?: string
4647
roblox?: string
4748
okta?: string
4849
ory?: string

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ export interface LiveChatConfig {
8181
userURL?: string
8282

8383
/**
84-
* LiveChat OAuth Scope. accounts--my:ro is always applied to get user profile.
85-
* @default ['accounts--my:ro']
84+
* LiveChat OAuth Scope. If not provided, the default scope from LiveChat will be used.
8685
* @example ['accounts--my:ro', 'chats--my:ro']
8786
*/
8887
scope?: string[]
@@ -104,7 +103,6 @@ export function defineOAuthLiveChatEventHandler({
104103
authorizationURL: 'https://accounts.livechat.com',
105104
tokenURL: 'https://accounts.livechat.com/v2/token',
106105
userURL: 'https://accounts.livechat.com/v2/accounts/me',
107-
scope: [],
108106
authorizationParams: {
109107
state: randomUUID(),
110108
},
@@ -122,17 +120,14 @@ export function defineOAuthLiveChatEventHandler({
122120
const query = getQuery<{ code?: string }>(event)
123121
const redirectURL = config.redirectURL || getOAuthRedirectURL(event)
124122

125-
// Ensure accounts--my:ro is always applied.
126-
const scope = [...new Set([...config.scope!, 'accounts--my:ro'])].join(' ')
127-
128123
if (!query.code) {
129124
return sendRedirect(
130125
event,
131126
withQuery(config.authorizationURL!, {
132127
client_id: config.clientId,
133128
redirect_uri: redirectURL,
134129
response_type: 'code',
135-
scope,
130+
scope: config.scope?.length ? config.scope.join(' ') : undefined,
136131
...config.authorizationParams,
137132
}),
138133
)

0 commit comments

Comments
 (0)