(clientId, refreshToken, options = {})
| 80 | } |
| 81 | |
| 82 | async function exchangeRefreshToken(clientId, refreshToken, options = {}) { |
| 83 | const fetchImpl = getFetchImpl(options.fetchImpl); |
| 84 | const strategy = resolveTokenStrategy(options.strategyName); |
| 85 | const body = new URLSearchParams({ |
| 86 | client_id: clientId, |
| 87 | grant_type: 'refresh_token', |
| 88 | refresh_token: refreshToken, |
| 89 | ...(strategy.extraData || {}), |
| 90 | }); |
| 91 | const response = await fetchImpl(strategy.url, { |
| 92 | method: 'POST', |
| 93 | headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, |
| 94 | body: body.toString(), |
| 95 | signal: options.signal, |
| 96 | }); |
| 97 | |
| 98 | if (!response.ok) { |
| 99 | throw new Error(`${strategy.name}: ${await getResponseErrorText(response)}`); |
| 100 | } |
| 101 | |
| 102 | const data = await response.json(); |
| 103 | if (!data.access_token) { |
| 104 | throw new Error(`${strategy.name}: token response missing access_token`); |
| 105 | } |
| 106 | |
| 107 | return { |
| 108 | ...data, |
| 109 | tokenStrategy: strategy.name, |
| 110 | }; |
| 111 | } |
| 112 | |
| 113 | async function fetchGraphMessages(accessToken, options = {}) { |
| 114 | const fetchImpl = getFetchImpl(options.fetchImpl); |
no test coverage detected