MCPcopy Create free account
hub / github.com/massCodeIO/massCode / applyAuth

Function applyAuth

src/main/ipc/handlers/http.ts:91–113  ·  view source on GitHub ↗
(
  auth: HttpAuth,
  headers: HttpHeaderEntry[],
)

Source from the content-addressed store, hash-verified

89}
90
91export function applyAuth(
92 auth: HttpAuth,
93 headers: HttpHeaderEntry[],
94): HttpHeaderEntry[] {
95 if (auth.type === 'bearer' && auth.token) {
96 return [
97 ...headers,
98 { key: 'Authorization', value: `Bearer ${auth.token}` },
99 ]
100 }
101
102 if (auth.type === 'basic' && auth.username !== undefined) {
103 const credentials = Buffer.from(
104 `${auth.username}:${auth.password ?? ''}`,
105 ).toString('base64')
106 return [
107 ...headers,
108 { key: 'Authorization', value: `Basic ${credentials}` },
109 ]
110 }
111
112 return headers
113}
114
115function buildUrl(rawUrl: string, query: HttpQueryEntry[]): string {
116 const url = new URL(rawUrl)

Callers 1

executeHttpRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected