Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
const authOptionsWithNoUserPoolId: AuthOptions = {
userPoolId: null,
userPoolWebClientId: 'awsUserPoolsWebClientId',
region: 'region',
identityPoolId: 'awsCognitoIdentityPoolId',
mandatorySignIn: false,
};
const userPool = new CognitoUserPool({
UserPoolId: authOptions.userPoolId,
ClientId: authOptions.userPoolWebClientId,
});
const idToken = new CognitoIdToken({ IdToken: 'idToken' });
const accessToken = new CognitoAccessToken({ AccessToken: 'accessToken' });
const session = new CognitoUserSession({
IdToken: idToken,
AccessToken: accessToken,
});
const cognitoCredentialSpyon = jest
.spyOn(CognitoIdentityCredentials.prototype, 'get')
.mockImplementation(callback => {
callback(null);
});
describe('for react native', () => {
describe('currentUserCredentials test', () => {
test('with federated info', async () => {
export function newSession({ idToken, refreshToken, accessToken } = {}) {
const token = makeToken();
return new CognitoUserSession({
IdToken: new CognitoIdToken({ IdToken: idToken || token }),
RefreshToken: new CognitoRefreshToken({ RefreshToken: refreshToken || token }),
AccessToken: new CognitoAccessToken({ AccessToken: accessToken || token })
});
}
return new Promise((resolve, reject) => {
if (sessionData) {
let accessToken = new CognitoAccessToken({ AccessToken: sessionData.accessToken.jwtToken });
let idToken = new CognitoIdToken({ IdToken: sessionData.idToken.jwtToken });
let refreshToken = new CognitoRefreshToken({ RefreshToken: sessionData.refreshToken.token });
let session = new CognitoUserSession({
IdToken: idToken,
AccessToken: accessToken,
RefreshToken: refreshToken,
ClockDrift: sessionData.clockDrift,
});
if (!session.isValid()) {
dispatch(refreshSession()).then((result) => {
resolve(result);
}, error => {
dispatch(logoutAction());
reject(error.response.message);
});