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 86% rename from playground/server/routes/auth/livechat.ts rename to playground/server/routes/auth/livechat.get.ts index de064e96..18eea147 100644 --- a/playground/server/routes/auth/livechat.ts +++ b/playground/server/routes/auth/livechat.get.ts @@ -1,9 +1,8 @@ export default defineOAuthLiveChatEventHandler({ - config: {}, async onSuccess(event, { user }) { await setUserSession(event, { user: { - livechat: user, + livechat: user.name, }, loggedInAt: Date.now(), }) diff --git a/src/runtime/server/lib/oauth/livechat.ts b/src/runtime/server/lib/oauth/livechat.ts index b028c734..98946756 100644 --- a/src/runtime/server/lib/oauth/livechat.ts +++ b/src/runtime/server/lib/oauth/livechat.ts @@ -81,11 +81,10 @@ export interface LiveChatConfig { userURL?: string /** - * LiveChat OAuth Scope. accounts--my:ro is always applied to get user profile. - * @default ['accounts--my:ro'] - * @example ['accounts--my:ro', 'chats--my:ro'] + * LiveChat OAuth Scope. + * @example 'accounts--my:ro chats--my:ro' */ - scope?: string[] + scope?: string /** * Extra authorization parameters to provide to the authorization URL @@ -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(), }, @@ -115,16 +113,12 @@ export function defineOAuthLiveChatEventHandler({ event, 'livechat', ['clientId', 'clientSecret'], - onError, ) } 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 +126,7 @@ export function defineOAuthLiveChatEventHandler({ client_id: config.clientId, redirect_uri: redirectURL, response_type: 'code', - scope, + scope: config.scope, ...config.authorizationParams, }), )