Skip to content

Commit

Permalink
fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored and RJiraya committed May 16, 2024
1 parent a9b06cc commit 3ad2353
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/@n8n/client-oauth2/src/ClientOAuth2Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ClientOAuth2TokenData extends Record<string, string | undefined
expires_in?: string;
scope?: string | undefined;
}

/**
* General purpose client token generator.
*/
Expand Down Expand Up @@ -77,7 +78,7 @@ export class ClientOAuth2Token {
const clientId = options.clientId;
const clientSecret = options.clientSecret;
const headers = { ...DEFAULT_HEADERS };
const body: Record<string, any> = {
const body: Record<string, string> = {
refresh_token: this.refreshToken,
grant_type: 'refresh_token',
};
Expand All @@ -93,8 +94,8 @@ export class ClientOAuth2Token {
{
url: options.accessTokenUri,
method: 'POST',
headers: headers,
body: body,
headers,
body,
},
options,
);
Expand Down
13 changes: 10 additions & 3 deletions packages/@n8n/client-oauth2/test/CredentialsFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ describe('CredentialsFlow', () => {
const token = await authClient.credentials.getToken();
expect(token.accessToken).toEqual(config.accessToken);

mockRefreshCall();
const requestPromise = mockRefreshCall();
const token1 = await token.refresh();
await requestPromise;

expect(token1).toBeInstanceOf(ClientOAuth2Token);
expect(token1.accessToken).toEqual(config.refreshedAccessToken);
expect(token1.tokenType).toEqual('bearer');
Expand All @@ -181,11 +183,16 @@ describe('CredentialsFlow', () => {
expect(token1.accessToken).toEqual(config.refreshedAccessToken);
expect(token1.tokenType).toEqual('bearer');
expect(headers?.authorization).toBe(undefined);
expect(body).toEqual('refresh_token=def456token&grant_type=refresh_token&client_id=abc&client_secret=123');
expect(body).toEqual(
'refresh_token=def456token&grant_type=refresh_token&client_id=abc&client_secret=123',
);
});

it('should make a request to get a new access token with authentication = "header"', async () => {
const authClient = createAuthClient({ scopes: ['notifications'], authentication: 'header' });
const authClient = createAuthClient({
scopes: ['notifications'],
authentication: 'header',
});
void mockTokenCall({ requestedScope: 'notifications' });

const token = await authClient.credentials.getToken();
Expand Down

0 comments on commit 3ad2353

Please sign in to comment.