Skip to content

Commit

Permalink
[#16] Implement backend for refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
manh-t committed Aug 29, 2023
1 parent 4c4a2b5 commit 1a6bf13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/adapters/Authentication/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { post } from 'adapters/Base';
import { config } from 'config';

import { signIn } from '.';
import { refreshToken, signIn } from '.';

jest.mock('adapters/Base');
jest.mock('config');
Expand Down Expand Up @@ -40,4 +40,24 @@ describe('AuthenticationAdapter', () => {
});
});
});

describe('refreshToken', () => {
describe('given a refresh token', () => {
it('calls the post method from the base adapter', () => {
const token = 'refresh token';

const expectedPath = 'oauth/token';
const expectedPayload = {
grantType: 'refresh_token',
clientId: config().clientId,
clientSecret: config().clientSecret,
refreshToken: token,
};

refreshToken(token);

expect(post).toHaveBeenCalledWith(expectedPath, expectedPayload);
});
});
});
});
8 changes: 8 additions & 0 deletions src/adapters/Authentication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ export const signIn = (email: string, password: string) =>
email: email,
password: password,
});

export const refreshToken = (refreshToken: string) =>
post('oauth/token', {
clientId: config().clientId,
clientSecret: config().clientSecret,
grantType: 'refresh_token',
refreshToken: refreshToken,
});

0 comments on commit 1a6bf13

Please sign in to comment.