1 | |
2 | |
3 | * Generate an authentication link, using the Terra Authentication Widget |
4 | * Generates a link to redirect an end user to for them to select an integration and log in with their fitness data provider |
5 | */ |
6 | export async function main(auth: RT.Terra, body: Body) { |
7 | const url = new URL(`https://api.tryterra.co/v2/auth/generateWidgetSession`) |
8 |
|
9 | const response = await fetch(url, { |
10 | method: 'POST', |
11 | headers: { |
12 | 'dev-id': auth.devId, |
13 | 'Content-Type': 'application/json', |
14 | 'X-api-key': auth.apiKey |
15 | }, |
16 | body: JSON.stringify(body) |
17 | }) |
18 | if (!response.ok) { |
19 | const text = await response.text() |
20 | throw new Error(`${response.status} ${text}`) |
21 | } |
22 | return await response.json() |
23 | } |
24 |
|
25 | |
26 | |
27 | * This file was automatically generated by json-schema-to-typescript. |
28 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
29 | * and run json-schema-to-typescript to regenerate this file. |
30 | */ |
31 |
|
32 | export interface Body { |
33 | |
34 | * Comma separated list of providers to display on the device selection page. This overrides your selected sources on your dashboard |
35 | */ |
36 | providers?: string |
37 | |
38 | * Display language of the widget |
39 | */ |
40 | language?: string |
41 | |
42 | * Identifier of the end user on your system, such as a user ID or email associated with them |
43 | */ |
44 | reference_id?: string |
45 | |
46 | * URL the user is redirected to upon successful authentication |
47 | */ |
48 | auth_success_redirect_url?: string |
49 | |
50 | * URL the user is redirected to upon unsuccessful authentication |
51 | */ |
52 | auth_failure_redirect_url?: string |
53 | [k: string]: unknown |
54 | } |
55 |
|