This repository has been archived on 2024-09-11. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs-blog-newsletter/cronjob/node_modules/@aws-sdk/credential-provider-cognito-identity/dist-es/fromCognitoIdentity.js
2024-05-26 22:54:55 +02:00

32 lines
1.7 KiB
JavaScript

import { CredentialsProviderError } from "@smithy/property-provider";
import { resolveLogins } from "./resolveLogins";
export function fromCognitoIdentity(parameters) {
return async () => {
parameters.logger?.debug("@aws-sdk/credential-provider-cognito-identity", "fromCognitoIdentity");
const { GetCredentialsForIdentityCommand, CognitoIdentityClient } = await import("./loadCognitoIdentity");
const { Credentials: { AccessKeyId = throwOnMissingAccessKeyId(), Expiration, SecretKey = throwOnMissingSecretKey(), SessionToken, } = throwOnMissingCredentials(), } = await (parameters.client ??
new CognitoIdentityClient(Object.assign({}, parameters.clientConfig ?? {}, {
region: parameters.clientConfig?.region ?? parameters.parentClientConfig?.region,
}))).send(new GetCredentialsForIdentityCommand({
CustomRoleArn: parameters.customRoleArn,
IdentityId: parameters.identityId,
Logins: parameters.logins ? await resolveLogins(parameters.logins) : undefined,
}));
return {
identityId: parameters.identityId,
accessKeyId: AccessKeyId,
secretAccessKey: SecretKey,
sessionToken: SessionToken,
expiration: Expiration,
};
};
}
function throwOnMissingAccessKeyId() {
throw new CredentialsProviderError("Response from Amazon Cognito contained no access key ID");
}
function throwOnMissingCredentials() {
throw new CredentialsProviderError("Response from Amazon Cognito contained no credentials");
}
function throwOnMissingSecretKey() {
throw new CredentialsProviderError("Response from Amazon Cognito contained no secret key");
}