diff --git a/src/core/aws-web.core.ts b/src/core/aws-web.core.ts index c77c0c3..dd0f85f 100644 --- a/src/core/aws-web.core.ts +++ b/src/core/aws-web.core.ts @@ -1,4 +1,14 @@ -import { AWSWebCoreState, Body, LemonCredentials, LemonKMS, LemonOAuthToken, Params, WebCoreConfig, WebCoreService } from '../types'; +import { + AWSWebCoreState, + Body, + LemonCredentials, + LemonKMS, + LemonOAuthToken, + Params, + RefreshTokenBody, + WebCoreConfig, + WebCoreService, +} from '../types'; import { AWSStorageService, USE_X_LEMON_IDENTITY_KEY } from '../token-storage'; import { calcSignature, LoggerService } from '../utils'; import { AxiosRequestConfig, AxiosResponse } from 'axios'; @@ -234,11 +244,16 @@ export class AWSWebCore implements WebCoreService { const current = new Date().toISOString(); const signature = calcSignature(payload, current); + let body: RefreshTokenBody = { current, signature }; + if (domain && domain.length > 0) { + body = { ...body, domain }; + } + const response: AxiosResponse = await this.signedRequest( 'POST', url ? url : `${this.config.oAuthEndpoint}/oauth/${cached.authId}/refresh`, {}, - { current, signature, domain } + { ...body } ); const refreshToken = { ...response.data, diff --git a/src/types/lemon.ts b/src/types/lemon.ts index 3b3acc7..b81ad9e 100644 --- a/src/types/lemon.ts +++ b/src/types/lemon.ts @@ -197,3 +197,21 @@ export interface LoggerOption { */ showLogType?: boolean; } + +/** + * Interface representing the body of a refresh token request. + */ +export interface RefreshTokenBody { + /** + * The current token. + */ + current: string; + /** + * The signature of the token. + */ + signature: string; + /** + * Optional. The domain of the token. + */ + domain?: string; +}