Skip to content

Commit

Permalink
Merge pull request #20 from lemoncloud-io/feature/louis-fix-refresh
Browse files Browse the repository at this point in the history
fix: sign request with current, signature, and optional domain
  • Loading branch information
louis-lemon authored Jun 6, 2024
2 parents 4726afc + d913123 commit 367668b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/core/aws-web.core.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<LemonOAuthToken> = await this.signedRequest(
'POST',
url ? url : `${this.config.oAuthEndpoint}/oauth/${cached.authId}/refresh`,
{},
{ current, signature, domain }
{ ...body }
);
const refreshToken = {
...response.data,
Expand Down
18 changes: 18 additions & 0 deletions src/types/lemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 367668b

Please sign in to comment.