2121
2222import { INTERNAL_PREFIX } from '@workfront/api-constants'
2323
24+ export interface IImsCredentials {
25+ imsToken : string
26+ imsOrgId : string
27+ }
28+
2429export interface IHttpOptions {
2530 path ?: string
2631 method ?: string
@@ -30,6 +35,8 @@ export interface IHttpOptions {
3035 sessionID ?: string
3136 'X-XSRF-TOKEN' ?: string
3237 apiKey ?: string
38+ Authorization ?: string
39+ 'x-gw-ims-org-id' ?: string
3340 }
3441}
3542export interface IApiConfig {
@@ -575,6 +582,20 @@ export class Api {
575582 delete this . _httpOptions . headers [ 'X-XSRF-TOKEN' ]
576583 }
577584 }
585+ /**
586+ * Sets the 'x-gw-ims-org-id' and 'Authorization' header
587+ * @memberof Api
588+ * @param {IImsCredentials } imsCredentials ims token and ims org id to set
589+ */
590+ setImsCredentials ( imsCredentials ?: IImsCredentials ) {
591+ if ( imsCredentials ) {
592+ this . _httpOptions . headers . Authorization = 'Bearer ' + imsCredentials . imsToken
593+ this . _httpOptions . headers [ 'x-gw-ims-org-id' ] = imsCredentials . imsOrgId
594+ } else {
595+ delete this . _httpOptions . headers . Authorization
596+ delete this . _httpOptions . headers [ 'x-gw-ims-org-id' ]
597+ }
598+ }
578599
579600 uploadFileContent ( fileContent , filename : string ) {
580601 const data = new FormData ( )
@@ -591,6 +612,12 @@ export class Api {
591612 headers . append ( 'X-XSRF-TOKEN' , this . _httpOptions . headers [ 'X-XSRF-TOKEN' ] )
592613 } else if ( this . _httpOptions . headers . apiKey ) {
593614 headers . append ( 'apiKey' , this . _httpOptions . headers . apiKey )
615+ } else if (
616+ this . _httpOptions . headers . Authorization &&
617+ this . _httpOptions . headers [ 'x-gw-ims-org-id' ]
618+ ) {
619+ headers . append ( 'Authorization' , this . _httpOptions . headers . Authorization )
620+ headers . append ( 'x-gw-ims-org-id' , this . _httpOptions . headers [ 'x-gw-ims-org-id' ] )
594621 }
595622 return headers
596623 }
0 commit comments