(params: OauthCredsDiffParams)
| 15 | * admins can overwrite an unusable stored secret instead of getting a 500. |
| 16 | */ |
| 17 | export async function oauthCredsChanged(params: OauthCredsDiffParams): Promise<boolean> { |
| 18 | const clientIdChanged = |
| 19 | params.incomingClientIdProvided && |
| 20 | (params.incomingClientId || null) !== (params.currentClientId ?? null) |
| 21 | |
| 22 | let clientSecretChanged = false |
| 23 | if (params.incomingClientSecretProvided) { |
| 24 | if (!params.incomingClientSecret) { |
| 25 | clientSecretChanged = params.currentEncryptedClientSecret != null |
| 26 | } else if (!params.currentEncryptedClientSecret) { |
| 27 | clientSecretChanged = true |
| 28 | } else { |
| 29 | try { |
| 30 | const { decrypted } = await decryptSecret(params.currentEncryptedClientSecret) |
| 31 | clientSecretChanged = decrypted !== params.incomingClientSecret |
| 32 | } catch { |
| 33 | clientSecretChanged = true |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return clientIdChanged || clientSecretChanged |
| 39 | } |
no test coverage detected