({ request }: ActionFunctionArgs)
| 7 | |
| 8 | /** Used to create an AuthorizationCode, that can then be used to obtain a Personal Access Token by logging in with the provided URL */ |
| 9 | export async function action({ request }: ActionFunctionArgs) { |
| 10 | logger.info("Creating AuthorizationCode", { url: request.url }); |
| 11 | |
| 12 | // Ensure this is a POST request |
| 13 | if (request.method.toUpperCase() !== "POST") { |
| 14 | return { status: 405, body: "Method Not Allowed" }; |
| 15 | } |
| 16 | |
| 17 | //there is no authentication on this endpoint, anyone can create an AuthorizationCode. |
| 18 | //they're only used to allow a user to login, when they'll then receive a Personal Access Token |
| 19 | |
| 20 | try { |
| 21 | const authorizationCode = await createAuthorizationCode(); |
| 22 | const responseJson: CreateAuthorizationCodeResponse = { |
| 23 | authorizationCode: authorizationCode.code, |
| 24 | url: `${env.APP_ORIGIN}/account/authorization-code/${authorizationCode.code}`, |
| 25 | }; |
| 26 | |
| 27 | return json(responseJson); |
| 28 | } catch (error) { |
| 29 | if (error instanceof Error) { |
| 30 | logger.error("Error creating AuthorizationCode", { |
| 31 | url: request.url, |
| 32 | error: error.message, |
| 33 | }); |
| 34 | |
| 35 | return json({ error: error.message }, { status: 400 }); |
| 36 | } |
| 37 | |
| 38 | return json({ error: "Something went wrong" }, { status: 500 }); |
| 39 | } |
| 40 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…