Workforce: bearer token only, remove email/password fields
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e758add8ae
commit
24f3fcdc7b
2 changed files with 7 additions and 20 deletions
|
|
@ -30,7 +30,7 @@ export const INTEGRATIONS = {
|
|||
workforce: {
|
||||
name: 'Workforce',
|
||||
configFields: ['base_url', 'sync_hours'],
|
||||
secretFields: ['bearer_token', 'email', 'password'],
|
||||
secretFields: ['bearer_token'],
|
||||
},
|
||||
smtp: {
|
||||
name: 'SMTP Email',
|
||||
|
|
|
|||
|
|
@ -88,26 +88,13 @@ export async function integrationRoutes(app) {
|
|||
if (req.params.slug === 'newbook') await newbookTest(creds)
|
||||
else if (req.params.slug === 'resos') await resosTest(creds)
|
||||
else if (req.params.slug === 'workforce') {
|
||||
if (!creds.bearer_token) throw new Error('Workforce bearer token not configured')
|
||||
const baseUrl = creds.base_url || 'https://my.workforce.com'
|
||||
if (creds.bearer_token) {
|
||||
// Test bearer token directly with a lightweight API call
|
||||
const res = await fetch(`${baseUrl}/api/v2/users?page=1&page_size=1`, {
|
||||
headers: { Authorization: `Bearer ${creds.bearer_token}` },
|
||||
signal: AbortSignal.timeout(8000),
|
||||
})
|
||||
if (!res.ok) throw new Error(`Workforce bearer token invalid (${res.status})`)
|
||||
} else {
|
||||
if (!creds.email || !creds.password) throw new Error('No bearer token or email/password configured')
|
||||
const res = await fetch(`${baseUrl}/api/oauth/token`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: new URLSearchParams({ grant_type: 'password', username: creds.email, password: creds.password, scope: 'platform' }).toString(),
|
||||
signal: AbortSignal.timeout(8000),
|
||||
})
|
||||
if (!res.ok) throw new Error(`Workforce auth failed (${res.status})`)
|
||||
const data = await res.json()
|
||||
if (!data.access_token) throw new Error('No access token returned')
|
||||
}
|
||||
const res = await fetch(`${baseUrl}/api/v2/users/me`, {
|
||||
headers: { Authorization: `Bearer ${creds.bearer_token}` },
|
||||
signal: AbortSignal.timeout(8000),
|
||||
})
|
||||
if (!res.ok) throw new Error(`Workforce bearer token invalid (${res.status})`)
|
||||
}
|
||||
else if (req.params.slug === 'smtp') {
|
||||
const nodemailer = await import('nodemailer')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue