( authorizationHeader?: string, )
| 48 | } |
| 49 | |
| 50 | export function isIntegrationTokenAuthorized( |
| 51 | authorizationHeader?: string, |
| 52 | ): boolean { |
| 53 | const enabled = store.preferences.get('api.integrations.enabled') as boolean |
| 54 | const tokenHash = store.preferences.get('api.integrations.tokenHash') as |
| 55 | | string |
| 56 | | null |
| 57 | |
| 58 | if (!enabled || !tokenHash || !authorizationHeader) { |
| 59 | return false |
| 60 | } |
| 61 | |
| 62 | const bearerPrefix = 'bearer ' |
| 63 | if (!authorizationHeader.toLowerCase().startsWith(bearerPrefix)) { |
| 64 | return false |
| 65 | } |
| 66 | |
| 67 | const token = authorizationHeader.slice(bearerPrefix.length).trim() |
| 68 | if (!token) { |
| 69 | return false |
| 70 | } |
| 71 | |
| 72 | return isSameHash(hashIntegrationToken(token), tokenHash) |
| 73 | } |
no test coverage detected