Use Workforce bearer token directly if configured, skip OAuth
If a bearer_token is stored in settings, getWorkforceToken() returns it immediately without doing an OAuth password grant. Validation accepts either bearer_token or email+password. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8d6fd71800
commit
75d373c2c5
1 changed files with 9 additions and 1 deletions
|
|
@ -13,7 +13,9 @@ async function getWorkforceCreds() {
|
||||||
})
|
})
|
||||||
if (!res.ok) throw new Error(`Failed to fetch Workforce credentials from settings: ${res.status}`)
|
if (!res.ok) throw new Error(`Failed to fetch Workforce credentials from settings: ${res.status}`)
|
||||||
const creds = await res.json()
|
const creds = await res.json()
|
||||||
if (!creds.email || !creds.password) throw new Error('Workforce credentials not configured in settings')
|
if (!creds.bearer_token && (!creds.email || !creds.password)) {
|
||||||
|
throw new Error('Workforce credentials not configured in settings — set a bearer token or email/password')
|
||||||
|
}
|
||||||
_credsCache = { creds, expires_at: Date.now() + 5 * 60_000 }
|
_credsCache = { creds, expires_at: Date.now() + 5 * 60_000 }
|
||||||
return creds
|
return creds
|
||||||
}
|
}
|
||||||
|
|
@ -21,6 +23,12 @@ async function getWorkforceCreds() {
|
||||||
async function getWorkforceToken() {
|
async function getWorkforceToken() {
|
||||||
const creds = await getWorkforceCreds()
|
const creds = await getWorkforceCreds()
|
||||||
const baseUrl = creds.base_url || 'https://my.workforce.com'
|
const baseUrl = creds.base_url || 'https://my.workforce.com'
|
||||||
|
|
||||||
|
// Use bearer token directly if configured — no OAuth exchange needed
|
||||||
|
if (creds.bearer_token) {
|
||||||
|
return { token: creds.bearer_token, baseUrl }
|
||||||
|
}
|
||||||
|
|
||||||
if (_tokenCache && _tokenCache.base_url === baseUrl && Date.now() < _tokenCache.expires_at) {
|
if (_tokenCache && _tokenCache.base_url === baseUrl && Date.now() < _tokenCache.expires_at) {
|
||||||
return { token: _tokenCache.access_token, baseUrl }
|
return { token: _tokenCache.access_token, baseUrl }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue