export type TokenType = 'card' | 'event'; export type GetApiAuthProfileTokenArgs = {type: TokenType, id?: string | undefined, accept: 'image/svg+xml' | 'text/plain'}; export type GetApiAuthProfileTokenOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get an access token for a specific service | Ottieni un token di accesso per un servizio specifico * * GET /auth/profile/token */ export const getApiAuthProfileToken = async (args: GetApiAuthProfileTokenArgs, options?: GetApiAuthProfileTokenOptions) => { const {baseUrl = "https://app.didattica.polito.it/api", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/svg+xml") if (args.type != null) query.append("type", String(args.type)) if (args.id != null) query.append("id", String(args.id)) if (args.accept != null) headers.set("accept", String(args.accept)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/auth/profile/token${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };