Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): add signInDetails on refreshTokens action #13153

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jest.mock('@aws-amplify/core', () => ({
},
}));

const mockAssertTokenProviderConfig = assertTokenProviderConfig as jest.Mock;

describe('tokenOrchestrator', () => {
const mockTokenRefresher = jest.fn();
const mockTokenStore = {
Expand All @@ -36,14 +34,19 @@ describe('tokenOrchestrator', () => {
describe('refreshTokens method', () => {
it('calls the set tokenRefresher, tokenStore and Hub while refreshing tokens', async () => {
const testUsername = 'username';
const testSignInDetails= {
authFlowType:'CUSTOM_WITHOUT_SRP',
loginId: testUsername
} as const;
const testInputTokens = {
accessToken: {
payload: {},
},
clockDrift: 400000,
username: testUsername,
signInDetails:testSignInDetails
};

// mock tokens should not include signInDetails
const mockTokens: CognitoAuthTokens = {
accessToken: {
payload: {},
Expand Down Expand Up @@ -71,6 +74,7 @@ describe('tokenOrchestrator', () => {

// ensure the result is correct
expect(newTokens).toEqual(mockTokens);
expect(newTokens?.signInDetails).toEqual(testSignInDetails)
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
username: string;
}): Promise<CognitoAuthTokens | null> {
try {
const { signInDetails } = tokens;
const newTokens = await this.getTokenRefresher()({
tokens,
authConfig: this.authConfig,
username,
});

newTokens.signInDetails = signInDetails;
await this.setTokens({ tokens: newTokens });
Hub.dispatch('auth', { event: 'tokenRefresh' }, 'Auth', AMPLIFY_SYMBOL);

Expand Down
Loading