diff --git a/playground/app.vue b/playground/app.vue index 91f6ecc0..07cbafb0 100644 --- a/playground/app.vue +++ b/playground/app.vue @@ -248,6 +248,12 @@ const providers = computed(() => disabled: Boolean(user.value?.heroku), icon: 'i-simple-icons-heroku', }, + { + label: user.value?.livechat || 'Livechat', + to: '/auth/livechat', + disabled: Boolean(user.value?.livechat), + icon: 'i-simple-icons-livechat', + }, { label: user.value?.roblox || 'Roblox', to: '/auth/roblox', diff --git a/playground/auth.d.ts b/playground/auth.d.ts index 1f182324..fe8cd3a8 100644 --- a/playground/auth.d.ts +++ b/playground/auth.d.ts @@ -43,6 +43,7 @@ declare module '#auth-utils' { salesforce?: string slack?: string heroku?: string + livechat?: string roblox?: string okta?: string ory?: string diff --git a/playground/server/routes/auth/livechat.ts b/playground/server/routes/auth/livechat.get.ts similarity index 78% rename from playground/server/routes/auth/livechat.ts rename to playground/server/routes/auth/livechat.get.ts index de064e96..631902fa 100644 --- a/playground/server/routes/auth/livechat.ts +++ b/playground/server/routes/auth/livechat.get.ts @@ -1,14 +1,12 @@ export default defineOAuthLiveChatEventHandler({ - config: {}, async onSuccess(event, { user }) { await setUserSession(event, { user: { - livechat: user, + livechat: user.name, }, loggedInAt: Date.now(), }) return sendRedirect(event, '/') }, - async onError() {}, }) diff --git a/src/runtime/server/lib/oauth/livechat.ts b/src/runtime/server/lib/oauth/livechat.ts index b028c734..2cafb2dd 100644 --- a/src/runtime/server/lib/oauth/livechat.ts +++ b/src/runtime/server/lib/oauth/livechat.ts @@ -81,8 +81,7 @@ export interface LiveChatConfig { userURL?: string /** - * LiveChat OAuth Scope. accounts--my:ro is always applied to get user profile. - * @default ['accounts--my:ro'] + * LiveChat OAuth Scope. If not provided, the default scope from LiveChat will be used. * @example ['accounts--my:ro', 'chats--my:ro'] */ scope?: string[] @@ -104,7 +103,6 @@ export function defineOAuthLiveChatEventHandler({ authorizationURL: 'https://accounts.livechat.com', tokenURL: 'https://accounts.livechat.com/v2/token', userURL: 'https://accounts.livechat.com/v2/accounts/me', - scope: [], authorizationParams: { state: randomUUID(), }, @@ -122,9 +120,6 @@ export function defineOAuthLiveChatEventHandler({ const query = getQuery<{ code?: string }>(event) const redirectURL = config.redirectURL || getOAuthRedirectURL(event) - // Ensure accounts--my:ro is always applied. - const scope = [...new Set([...config.scope!, 'accounts--my:ro'])].join(' ') - if (!query.code) { return sendRedirect( event, @@ -132,7 +127,7 @@ export function defineOAuthLiveChatEventHandler({ client_id: config.clientId, redirect_uri: redirectURL, response_type: 'code', - scope, + scope: config.scope?.length ? config.scope.join(' ') : undefined, ...config.authorizationParams, }), )