Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions playground/auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ declare module '#auth-utils' {
salesforce?: string
slack?: string
heroku?: string
livechat?: string
roblox?: string
okta?: string
ory?: string
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {},
})
9 changes: 2 additions & 7 deletions src/runtime/server/lib/oauth/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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(),
},
Expand All @@ -122,17 +120,14 @@ 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,
withQuery(config.authorizationURL!, {
client_id: config.clientId,
redirect_uri: redirectURL,
response_type: 'code',
scope,
scope: config.scope?.length ? config.scope.join(' ') : undefined,
...config.authorizationParams,
}),
)
Expand Down
Loading