(account: string, refreshToken: string)
| 134 | } |
| 135 | |
| 136 | async function refreshAccessToken(account: string, refreshToken: string) { |
| 137 | const response = await fetch(`https://${account}.snowflakecomputing.com/oauth/token-request`, { |
| 138 | method: "POST", |
| 139 | headers: { |
| 140 | ...authHeaders(), |
| 141 | Authorization: authBasicHeader(), |
| 142 | }, |
| 143 | body: new URLSearchParams({ |
| 144 | grant_type: "refresh_token", |
| 145 | refresh_token: refreshToken, |
| 146 | client_id: OAUTH_CLIENT_ID, |
| 147 | }).toString(), |
| 148 | }) |
| 149 | |
| 150 | if (!response.ok) { |
| 151 | const detail = await response.text().catch(() => "") |
| 152 | throw new Error(`Snowflake token refresh failed (${response.status})${detail ? `: ${detail}` : ""}`) |
| 153 | } |
| 154 | |
| 155 | const token = (await response.json()) as TokenResponse |
| 156 | if (!token.access_token) throw new Error("Snowflake refresh response did not include access_token") |
| 157 | return token |
| 158 | } |
| 159 | |
| 160 | async function startOAuthServer() { |
| 161 | if (oauthServer) return |
no test coverage detected