Skip to content

[Breaking] Remove scope assumption with LiveChat login and fix playground #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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,9 +1,8 @@
export default defineOAuthLiveChatEventHandler({
config: {},
async onSuccess(event, { user }) {
await setUserSession(event, {
user: {
livechat: user,
livechat: user.name,
},
loggedInAt: Date.now(),
})
Expand Down
14 changes: 4 additions & 10 deletions src/runtime/server/lib/oauth/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -115,24 +113,20 @@ 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,
withQuery(config.authorizationURL!, {
client_id: config.clientId,
redirect_uri: redirectURL,
response_type: 'code',
scope,
scope: config.scope,
...config.authorizationParams,
}),
)
Expand Down
Loading