Skip to content

Commit

Permalink
Add comments, fix avatar API call
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Kabo committed Feb 14, 2024
1 parent 77454b2 commit 8e3e883
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions server/idapiProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ const idapiOrOAuthHeaders = ({
}
};

/**
* Prepares the options object for a fetch request to IDAPI
* or Avatar API (AAPI).
*
* @param options - The options object to prepare
* @param options.sendAuthHeader - Whether to send the access token or IDAPI cookies
* in the request
* @param options.useOkta - Whether to use Okta for authentication
* @param options.path - The path to the IDAPI endpoint (e.g. '/user/me')
* @param options.subdomain - The subdomain of the IDAPI endpoint
* (e.g. 'idapi' or 'avatar')
* @param options.method - The HTTP method to use
* @param options.cookies - The cookies coming from the client. These are used to
* build the security and cookie headers in the request
* @param options.signedCookies - The signed cookies coming from the client, also
* used to build the security and cookie headers in the request
* @param options.config - The IDAPI configuration object
* @returns The options object for the fetch request
*/
export const setOptions = ({
sendAuthHeader,
useOkta,
Expand Down Expand Up @@ -170,6 +189,8 @@ export const idapiFetch = async <T>({
* @param url The IDAPI endpoint to hit
* @param method The HTTP method to use (default: 'GET')
* @param processData A function to process the JSON response (optional)
* @param sendAuthHeader Whether to send the access token or IDAPI cookies
* in the request (default: false)
* @returns An Express route handler
*/
export const idapiProxyHandler =
Expand Down
2 changes: 1 addition & 1 deletion server/routes/aapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ router.get(
}
const { useOkta } = await getOktaConfig();
const options = setOptions({
sendAuthHeader: false,
sendAuthHeader: true,
useOkta,
path: '/v1/avatars/user/me/active',
subdomain: 'avatar',
Expand Down

0 comments on commit 8e3e883

Please sign in to comment.