(req, res)
| 125 | never, |
| 126 | { code: string; state?: string } |
| 127 | > = async (req, res) => { |
| 128 | const { code, state } = req.query; |
| 129 | |
| 130 | if (!req.context.vaultClient) { |
| 131 | res.status(501).send({ error: "Vault integration is not configured." }); |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | if (!state) { |
| 136 | res.status(400).send({ error: "No state provided" }); |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | const stateData = stateMap.get(state); |
| 141 | |
| 142 | if (!stateData) { |
| 143 | res.status(400).send({ error: "Invalid state" }); |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | if (stateData.actorEntityId !== req.user?.entity.metadata.recordId.entityId) { |
| 148 | res.status(403).send({ error: "State mismatch" }); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | const now = new Date(); |
| 153 | if (stateData.expires < now) { |
| 154 | res.status(400).send({ error: "State expired" }); |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | const { actorEntityId } = stateData; |
| 159 | |
| 160 | stateMap.delete(state); |
| 161 | |
| 162 | if (!linearClientId || !linearClientSecret) { |
| 163 | res.status(501).send({ error: "Linear integration is not configured." }); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | const formData = new URLSearchParams(); |
| 168 | formData.append("client_id", linearClientId); |
| 169 | formData.append("client_secret", linearClientSecret); |
| 170 | formData.append("code", code); |
| 171 | formData.append("redirect_uri", linearOAuthCallbackUrl); |
| 172 | formData.append("grant_type", "authorization_code"); |
| 173 | |
| 174 | const response = await fetch("https://api.linear.app/oauth/token", { |
| 175 | method: "POST", |
| 176 | body: formData.toString(), |
| 177 | headers: { |
| 178 | "content-type": "application/x-www-form-urlencoded", |
| 179 | }, |
| 180 | }).then( |
| 181 | (resp) => |
| 182 | resp.json() as Promise<{ access_token: string; expires_in: number }>, |
| 183 | ); |
| 184 |
nothing calls this directly
no test coverage detected