diff --git a/package.json b/package.json index 019bd7f17..5b111024f 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "license": "BSD-3-Clause", "dependencies": { "@apollo/client": "^3.2.1", + "cross-fetch": "^3.0.6", "dataloader": "^1.4.0", "graphql": "^15.3.0", "graphql-tools": "^7.0.4", diff --git a/rollup.config.js b/rollup.config.js index 582255057..501b75fb9 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -15,8 +15,8 @@ let external = FORMAT==='es' ? Object.keys(pkg.dependencies) .concat( ['castArray', 'get','isError', 'isObject', 'mapValues', 'reduce', 'omitBy', 'uniqBy', 'concat', 'uniqBy', 'differenceBy', 'forEach'].map(v => 'lodash/'+v), - ['graphql', '@graphql-tools/schema']) : - ['@graphql-tools/schema']; + ['graphql', '@graphql-tools/schema', 'cross-fetch']) : + ['@graphql-tools/schema', 'cross-fetch']; export default { diff --git a/src/batch-client/index.ts b/src/batch-client/index.ts index ed2a78c87..425d25cea 100644 --- a/src/batch-client/index.ts +++ b/src/batch-client/index.ts @@ -306,12 +306,14 @@ export class ZimbraBatchClient { private jwtToken?: string; private sessionHandler?: SessionHandler; private userAgent?: {}; + private authToken?: string; constructor(options: ZimbraClientOptions = {}) { this.sessionHandler = options.sessionHandler; this.userAgent = options.userAgent; this.jwtToken = options.jwtToken; this.csrfToken = options.csrfToken; + this.authToken = options.authToken; this.origin = options.zimbraOrigin !== undefined ? options.zimbraOrigin @@ -2001,6 +2003,9 @@ export class ZimbraBatchClient { ...(addCsrfToken && { csrfToken: this.csrfToken }), + ...(this.authToken && { + authToken: this.authToken + }), sessionId: this.sessionId || (this.sessionHandler && this.sessionHandler.readSessionId()), diff --git a/src/batch-client/types.ts b/src/batch-client/types.ts index a704239d7..d0b4371f3 100644 --- a/src/batch-client/types.ts +++ b/src/batch-client/types.ts @@ -69,6 +69,7 @@ export interface ZimbraClientOptions { soapPathname?: string; userAgent?: UserAgent; zimbraOrigin?: string; + authToken?: string; } export interface FreeBusyOptions { diff --git a/src/request/index.ts b/src/request/index.ts index 2a9c573a3..c84f8a684 100644 --- a/src/request/index.ts +++ b/src/request/index.ts @@ -13,7 +13,7 @@ import { SingleBatchRequestResponse, SOAPHeader } from './types'; - +import fetch from 'cross-fetch'; export const DEFAULT_HOSTNAME = '/@zimbra'; export const DEFAULT_SOAP_PATHNAME = '/service/soap'; @@ -243,6 +243,10 @@ export function jsonRequest( header.context.csrfToken = requestOptions.csrfToken; } + if (requestOptions.authToken) { + options.headers['Cookie'] = `ZM_AUTH_TOKEN=${requestOptions.authToken}`; + } + const body = { [soapRequestName]: soapCommandBody(options) }; @@ -255,6 +259,7 @@ export function jsonRequest( }; } + // @TODO: Remove third-party(cross-fetch) dependency. return fetch(url, { method: 'POST', credentials: options.credentials, diff --git a/src/request/types.ts b/src/request/types.ts index de4e841d0..cc9e034a7 100644 --- a/src/request/types.ts +++ b/src/request/types.ts @@ -27,6 +27,7 @@ export interface BaseRequestOptions { singleRequest?: boolean; soapPathname?: string; userAgent?: UserAgent; + authToken?: string; } export interface RequestOptions {