{"name":"@aws-sdk/credential-providers","version":"3.423.0","keywords":["aws","credentials"],"author":{"url":"https://aws.amazon.com/javascript/","name":"AWS SDK for JavaScript Team"},"license":"Apache-2.0","_id":"@aws-sdk/credential-providers@3.423.0","homepage":"https://github.com/aws/aws-sdk-js-v3/tree/main/packages/credential-providers","bugs":{"url":"https://github.com/aws/aws-sdk-js-v3/issues"},"dist":{"shasum":"a2a822c704ad4d4e4cf1e70163dab75affc4b23c","tarball":"http://registry-npm.ywwl.com/@aws-sdk/credential-providers/download/@aws-sdk/credential-providers-3.423.0.tgz","fileCount":59,"integrity":"sha512-jsjIrnu+bVUz2lekcg9wxpPlO8jWd9q26MP/rRwdkm9LHqroICjZY7tIYqSJliVkeSyJHJ9pq/jNDceWhy6a0A==","signatures":[{"sig":"MEUCIEgRKPhcP7JMniO+2vDeJm3Sr+GJdg68Tdh3RrIpY9unAiEAgut7RB7mIvfaAohZlsZJ4YxHrkOfSPeW8UUL15/93r4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":91310,"size":19709,"noattachment":false,"key":"/@aws-sdk/credential-providers/-/@aws-sdk/credential-providers-3.423.0.tgz"},"main":"./dist-cjs/index.js","types":"./dist-types/index.d.ts","module":"./dist-es/index.js","browser":"./dist-es/index.browser.js","engines":{"node":">=14.0.0"},"scripts":{"test":"jest","build":"concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'","clean":"rimraf ./dist-* && rimraf *.tsbuildinfo","build:es":"tsc -p tsconfig.es.json","build:cjs":"tsc -p tsconfig.cjs.json","build:types":"tsc -p tsconfig.types.json","extract:docs":"api-extractor run --local","build:include:deps":"lerna run --scope $npm_package_name --include-dependencies build","build:types:downlevel":"downlevel-dts dist-types dist-types/ts3.4"},"typedoc":{"entryPoint":"src/index.ts"},"_npmUser":{"name":"aws-sdk-bot","email":"aws-sdk-js-automation@amazon.com"},"repository":{"url":"git+https://github.com/aws/aws-sdk-js-v3.git","type":"git","directory":"packages/credential-providers"},"_npmVersion":"9.5.1","description":"A collection of credential providers, without requiring service clients like STS, Cognito","directories":{},"sideEffects":false,"_nodeVersion":"18.16.1","dependencies":{"tslib":"^2.5.0","@smithy/types":"^2.3.3","@aws-sdk/types":"3.418.0","@aws-sdk/client-sso":"3.423.0","@aws-sdk/client-sts":"3.423.0","@smithy/property-provider":"^2.0.0","@aws-sdk/client-cognito-identity":"3.423.0","@aws-sdk/credential-provider-env":"3.418.0","@aws-sdk/credential-provider-ini":"3.423.0","@aws-sdk/credential-provider-sso":"3.423.0","@smithy/credential-provider-imds":"^2.0.0","@aws-sdk/credential-provider-http":"3.423.0","@aws-sdk/credential-provider-node":"3.423.0","@aws-sdk/credential-provider-process":"3.418.0","@aws-sdk/credential-provider-web-identity":"3.418.0","@aws-sdk/credential-provider-cognito-identity":"3.423.0"},"react-native":"./dist-es/index.browser.js","typesVersions":{"<4.0":{"dist-types/*":["dist-types/ts3.4/*"]}},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"3.0.2","typedoc":"0.23.23","typescript":"~4.9.5","@types/node":"^14.14.31","concurrently":"7.0.0","downlevel-dts":"0.10.1","@tsconfig/recommended":"1.0.1"},"_npmOperationalInternal":{"tmp":"tmp/credential-providers_3.423.0_1696275240384_0.9485075998580506","host":"s3://npm-registry-packages"},"readme":"# @aws-sdk/credential-providers\n\n[![NPM version](https://img.shields.io/npm/v/@aws-sdk/credential-providers/latest.svg)](https://www.npmjs.com/package/@aws-sdk/credential-providers)\n[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/credential-providers.svg)](https://www.npmjs.com/package/@aws-sdk/credential-providers)\n\nA collection of all credential providers, with default clients.\n\n# Table of Contents\n\n1. [From Cognito Identity](#fromcognitoidentity)\n1. [From Cognito Identity Pool](#fromcognitoidentitypool)\n1. [From Temporary Credentials](#fromtemporarycredentials)\n1. [From Web Token](#fromwebtoken)\n   1. [Examples](#examples)\n1. [From Token File](#fromtokenfile)\n1. [From Instance and Container Metadata Service](#fromcontainermetadata-and-frominstancemetadata)\n1. [From HTTP(S)](#fromhttp)\n1. [From Shared INI files](#fromini)\n   1. [Sample Files](#sample-files)\n1. [From Environmental Variables](#fromenv)\n1. [From Credential Process](#fromprocess)\n   1. [Sample files](#sample-files-1)\n1. [From Single Sign-On Service](#fromsso)\n   1. [Supported Configuration](#supported-configuration)\n   1. [SSO login with AWS CLI](#sso-login-with-the-aws-cli)\n   1. [Sample Files](#sample-files-2)\n1. [From Node.js default credentials provider chain](#fromNodeProviderChain)\n\n## `fromCognitoIdentity()`\n\n- Uses `@aws-sdk/client-cognito-identity`\n- Available in browsers & native apps\n\nThe function `fromCognitoIdentity()` returns `CredentialsProvider` that retrieves credentials for\nthe provided identity ID. See [GetCredentialsForIdentity API][getcredentialsforidentity_api]\nfor more information.\n\n```javascript\nimport { fromCognitoIdentity } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromCognitoIdentity } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  region,\n  credentials: fromCognitoIdentity({\n    // Required. The unique identifier for the identity against which credentials\n    // will be issued.\n    identityId: \"us-east-1:128d0a74-c82f-4553-916d-90053example\",\n    // Optional. The ARN of the role to be assumed when multiple roles were received in the token\n    // from the identity provider.\n    customRoleArn: \"arn:aws:iam::1234567890:role/MYAPP-CognitoIdentity\",\n    // Optional. A set of name-value pairs that map provider names to provider tokens.\n    // Required when using identities associated with external identity providers such as Facebook.\n    logins: {\n      \"graph.facebook.com\": \"FBTOKEN\",\n      \"www.amazon.com\": \"AMAZONTOKEN\",\n      \"accounts.google.com\": \"GOOGLETOKEN\",\n      \"api.twitter.com\": \"TWITTERTOKEN'\",\n      \"www.digits.com\": \"DIGITSTOKEN\",\n    },\n    // Optional. Custom client config if you need overwrite default Cognito Identity client\n    // configuration.\n    clientConfig: { region },\n  }),\n});\n```\n\n## `fromCognitoIdentityPool()`\n\n- Uses `@aws-sdk/client-cognito-identity`\n- Available in browsers & native apps\n\nThe function `fromCognitoIdentityPool()` returns `AwsCredentialIdentityProvider` that calls [GetId API][getid_api]\nto obtain an `identityId`, then generates temporary AWS credentials with\n[GetCredentialsForIdentity API][getcredentialsforidentity_api], see\n[`fromCognitoIdentity()`](#fromcognitoidentity).\n\nResults from `GetId` are cached internally, but results from `GetCredentialsForIdentity` are not.\n\n```javascript\nimport { fromCognitoIdentityPool } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromCognitoIdentityPool } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  region,\n  credentials: fromCognitoIdentityPool({\n    // Required. The unique identifier for the identity pool from which an identity should be\n    // retrieved or generated.\n    identityPoolId: \"us-east-1:1699ebc0-7900-4099-b910-2df94f52a030\",\n    // Optional. A standard AWS account ID (9+ digits)\n    accountId: \"123456789\",\n    // Optional. A cache in which to store resolved Cognito IdentityIds.\n    cache: custom_storage,\n    // Optional. A unique identifier for the user used to cache Cognito IdentityIds on a per-user\n    // basis.\n    userIdentifier: \"user_0\",\n    // Optional. The ARN of the role to be assumed when multiple roles were received in the token\n    // from the identity provider.\n    customRoleArn: \"arn:aws:iam::1234567890:role/MYAPP-CognitoIdentity\",\n    // Optional. A set of name-value pairs that map provider names to provider tokens.\n    // Required when using identities associated with external identity providers such as Facebook.\n    logins: {\n      \"graph.facebook.com\": \"FBTOKEN\",\n      \"www.amazon.com\": \"AMAZONTOKEN\",\n      \"accounts.google.com\": \"GOOGLETOKEN\",\n      \"api.twitter.com\": \"TWITTERTOKEN\",\n      \"www.digits.com\": \"DIGITSTOKEN\",\n    },\n    // Optional. Custom client config if you need overwrite default Cognito Identity client\n    // configuration.\n    clientConfig: { region },\n  }),\n});\n```\n\n## `fromTemporaryCredentials()`\n\n- Uses `@aws-sdk/client-sts`\n- Available in browsers & native apps\n\nThe function `fromTemporaryCredentials` returns `AwsCredentialIdentityProvider` that retrieves temporary\ncredentials from [STS AssumeRole API][assumerole_api].\n\n```javascript\nimport { fromTemporaryCredentials } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromTemporaryCredentials } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  region,\n  credentials: fromTemporaryCredentials({\n    // Optional. The master credentials used to get and refresh temporary credentials from AWS STS.\n    // If skipped, it uses the default credential resolved by internal STS client.\n    masterCredentials: fromTemporaryCredentials({\n      params: { RoleArn: \"arn:aws:iam::1234567890:role/RoleA\" },\n    }),\n    // Required. Options passed to STS AssumeRole operation.\n    params: {\n      // Required. ARN of role to assume.\n      RoleArn: \"arn:aws:iam::1234567890:role/RoleB\",\n      // Optional. An identifier for the assumed role session. If skipped, it generates a random\n      // session name with prefix of 'aws-sdk-js-'.\n      RoleSessionName: \"aws-sdk-js-123\",\n      // Optional. The duration, in seconds, of the role session.\n      DurationSeconds: 3600,\n      // ... For more options see https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html\n    },\n    // Optional. Custom STS client configurations overriding the default ones.\n    clientConfig: { region },\n    // Optional. A function that returns a promise fulfilled with an MFA token code for the provided\n    // MFA Serial code. Required if `params` has `SerialNumber` config.\n    mfaCodeProvider: async (mfaSerial) => {\n      return \"token\";\n    },\n  }),\n});\n```\n\n## `fromWebToken()`\n\n- Uses `@aws-sdk/client-sts`\n- Available in browsers & native apps\n\nThe function `fromWebToken` returns `AwsCredentialIdentityProvider` that gets credentials calling\n[STS AssumeRoleWithWebIdentity API][assumerolewithwebidentity_api]\n\n```javascript\nimport { fromWebToken } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromWebToken } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  region,\n  credentials: fromWebToken({\n    // Required. ARN of the role that the caller is assuming.\n    roleArn: \"arn:aws:iam::1234567890:role/RoleA\",\n    // Required. The OAuth 2.0 access token or OpenID Connect ID token that is provided by the\n    // identity provider.\n    webIdentityToken: await openIdProvider(),\n    // Optional. Custom STS client configurations overriding the default ones.\n    clientConfig: { region },\n    // Optional. A function that assumes a role with web identity and returns a promise fulfilled\n    // with credentials for the assumed role.\n    roleAssumerWithWebIdentity,\n    // Optional. An identifier for the assumed role session.\n    roleSessionName: \"session_123\",\n    // Optional. The fully qualified host component of the domain name of the identity provider.\n    providerId: \"graph.facebook.com\",\n    // Optional. ARNs of the IAM managed policies that you want to use as managed session.\n    policyArns: [{ arn: \"arn:aws:iam::1234567890:policy/SomePolicy\" }],\n    // Optional. An IAM policy in JSON format that you want to use as an inline session policy.\n    policy: \"JSON_STRING\",\n    // Optional. The duration, in seconds, of the role session. Default to 3600.\n    durationSeconds: 7200,\n  }),\n});\n```\n\n### Examples\n\nYou can directly configure individual identity providers to access AWS resources using web identity\nfederation. AWS currently supports authenticating users using web identity federation through\nseveral identity providers:\n\n- [Login with Amazon](https://login.amazon.com/)\n\n- [Facebook Login](https://developers.facebook.com/docs/facebook-login/web/)\n\n- [Google Sign-in](https://developers.google.com/identity/)\n\nYou must first register your application with the providers that your application supports. Next,\ncreate an IAM role and set up permissions for it. The IAM role you create is then used to grant the\npermissions you configured for it through the respective identity provider. For example, you can set\nup a role that allows users who logged in through Facebook to have read access to a specific Amazon\nS3 bucket you control.\n\nAfter you have both an IAM role with configured privileges and an application registered with your\nchosen identity providers, you can set up the SDK to get credentials for the IAM role using helper\ncode, as follows:\n\nThe value in the ProviderId parameter depends on the specified identity provider. The value in the\nWebIdentityToken parameter is the access token retrieved from a successful login with the identity\nprovider. For more information on how to configure and retrieve access tokens for each identity\nprovider, see the documentation for the identity provider.\n\n## `fromContainerMetadata()` and `fromInstanceMetadata()`\n\n- Not available in browsers & native apps\n\n`fromContainerMetadata` and `fromInstanceMetadata` will create `AwsCredentialIdentityProvider` functions that\nread from the ECS container metadata service and the EC2 instance metadata service, respectively.\n\n```javascript\nimport { fromInstanceMetadata } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromInstanceMetadata } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  credentials: fromInstanceMetadata({\n    // Optional. The connection timeout (in milliseconds) to apply to any remote requests.\n    // If not specified, a default value of `1000` (one second) is used.\n    timeout: 1000,\n    // Optional. The maximum number of times any HTTP connections should be retried. If not\n    // specified, a default value of `0` will be used.\n    maxRetries: 0,\n  }),\n});\n```\n\n```javascript\nimport { fromContainerMetadata } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromContainerMetadata } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  credentials: fromContainerMetadata({\n    // Optional. The connection timeout (in milliseconds) to apply to any remote requests.\n    // If not specified, a default value of `1000` (one second) is used.\n    timeout: 1000,\n    // Optional. The maximum number of times any HTTP connections should be retried. If not\n    // specified, a default value of `0` will be used.\n    maxRetries: 0,\n  }),\n});\n```\n\nA `AwsCredentialIdentityProvider` function created with `fromContainerMetadata` will return a promise that will\nresolve with credentials for the IAM role associated with containers in an Amazon ECS task. Please\nsee [IAM Roles for Tasks][iam_roles_for_tasks] for more information on using IAM roles with Amazon\nECS.\n\nA `AwsCredentialIdentityProvider` function created with `fromInstanceMetadata` will return a promise that will\nresolve with credentials for the IAM role associated with an EC2 instance.\nPlease see [IAM Roles for Amazon EC2][iam_roles_for_ec2] for more information on using IAM roles\nwith Amazon EC2. Both IMDSv1 (a request/response method) and IMDSv2 (a session-oriented method) are\nsupported.\n\nPlease see [Configure the instance metadata service][config_instance_metadata] for more information.\n\n## `fromHttp()`\n\n- Available in browsers & native apps, without the EC2 and Container metadata components.\n\nThis creates a provider function that makes a `GET` request to\nany provided HTTPS URL. A limited set of HTTP destinations are also accepted.\n\nThis is a general form of the `fromContainerMetadata` function.\n\nThe server is expected to respond with the following format in JSON:\n\n```ts\ntype HttpProviderResponse = {\n  AccessKeyId: string;\n  SecretAccessKey: string;\n  Token: string;\n  AccountId?: string;\n  Expiration: string; // rfc3339\n};\n```\n\nThe acceptable non-HTTPS destinations are described in the validation error if encountered:\n\n```\nURL not accepted. It must either be HTTPS or match one of the following:\n  - loopback CIDR 127.0.0.0/8 or [::1/128]\n  - ECS container host 169.254.170.2\n  - EKS container host 169.254.170.23 or [fd00:ec2::23]\n```\n\nNode.js:\n\n```js\nimport { fromHttp } from \"@aws-sdk/credential-providers\";\n// const { fromHttp } = require(\"@aws-sdk/credential-providers\");\n\nconst client = new FooClient({\n  credentials: fromHttp({\n    /**\n     * If this value is provided, it will be used as-is.\n     */\n    awsContainerCredentialsFullUri: \"...\",\n    /**\n     * If this value is provided instead of the full URI, it\n     * will be appended to the default link local host of 169.254.170.2.\n     */\n    awsContainerCredentialsRelativeUri: \"...\",\n\n    /**\n     * Will be read on each credentials request to\n     * add an Authorization request header value.\n     */\n    awsContainerAuthorizationTokenFile: \"...\",\n\n    /**\n     * An alternative to awsContainerAuthorizationTokenFile,\n     * this is the token value itself.\n     */\n    awsContainerAuthorizationToken: \"...\",\n  }),\n});\n```\n\nIf not provided in the JavaScript code, the following process envrionment variables will\nbe read:\n\n```\nAWS_CONTAINER_CREDENTIALS_RELATIVE_URI\nAWS_CONTAINER_CREDENTIALS_FULL_URI\nAWS_CONTAINER_AUTHORIZATION_TOKEN_FILE\nAWS_CONTAINER_AUTHORIZATION_TOKEN\n```\n\nBrowsers:\n\n```js\nimport { fromHttp } from \"@aws-sdk/credential-providers\";\n\nconst client = new FooClient({\n  credentials: fromHttp({\n    /**\n     * BROWSER ONLY.\n     *\n     * In browsers, a relative URI is not allowed, and a full URI must be provided.\n     * HTTPS is required.\n     *\n     * This value is required for the browser environment.\n     */\n    credentialsFullUri: \"...\",\n\n    /**\n     * BROWSER ONLY.\n     *\n     * Providing this value will set an \"Authorization\" request\n     * header value on the GET request.\n     */\n    authorizationToken: \"...\",\n  }),\n});\n```\n\n## `fromIni()`\n\n- May use `@aws-sdk/client-sso` or `@aws-sdk/client-sts` depending\n  on how the file is configured.\n- Not available in browsers & native apps.\n\n`fromIni` creates `AwsCredentialIdentityProvider` functions that read from a shared credentials file at\n`~/.aws/credentials` and a shared configuration file at `~/.aws/config`. Both files are expected to\nbe INI formatted with section names corresponding to profiles. Sections in the credentials file are\ntreated as profile names, whereas profile sections in the config file must have the format of\n`[profile profile-name]`, except for the default profile. Please see the\n[sample files](#sample-files) below for examples of well-formed configuration and credentials files.\n\nProfiles that appear in both files will not be merged, and the version that appears in the\ncredentials file will be given precedence over the profile found in the config file.\n\n```javascript\nimport { fromIni } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromIni } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  credentials: fromIni({\n    // Optional. The configuration profile to use. If not specified, the provider will use the value\n    // in the `AWS_PROFILE` environment variable or a default of `default`.\n    profile: \"profile\",\n    // Optional. The path to the shared credentials file. If not specified, the provider will use\n    // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of\n    // `~/.aws/credentials`.\n    filepath: \"~/.aws/credentials\",\n    // Optional. The path to the shared config file. If not specified, the provider will use the\n    // value in the `AWS_CONFIG_FILE` environment variable or a default of `~/.aws/config`.\n    configFilepath: \"~/.aws/config\",\n    // Optional. A function that returns a a promise fulfilled with an MFA token code for the\n    // provided MFA Serial code. If a profile requires an MFA code and `mfaCodeProvider` is not a\n    // valid function, the credential provider promise will be rejected.\n    mfaCodeProvider: async (mfaSerial) => {\n      return \"token\";\n    },\n    // Optional. Custom STS client configurations overriding the default ones.\n    clientConfig: { region },\n  }),\n});\n```\n\n### Sample files\n\n#### `~/.aws/credentials`\n\n```ini\n[default]\naws_access_key_id=foo\naws_secret_access_key=bar\n\n[dev]\naws_access_key_id=foo2\naws_secret_access_key=bar2\n```\n\n#### `~/.aws/config`\n\n```ini\n[default]\naws_access_key_id=foo\naws_secret_access_key=bar\n\n[profile dev]\naws_access_key_id=foo2\naws_secret_access_key=bar2\n```\n\n#### profile with source profile\n\n```ini\n[second]\naws_access_key_id=foo\naws_secret_access_key=bar\n\n[first]\nsource_profile=second\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\n```\n\n#### profile with source provider\n\nYou can supply `credential_source` options to tell the SDK where to source credentials for the call\nto `AssumeRole`. The supported credential providers are listed below:\n\n```ini\n[default]\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\ncredential_source = Ec2InstanceMetadata\n```\n\n```ini\n[default]\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\ncredential_source = Environment\n```\n\n```ini\n[default]\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\ncredential_source = EcsContainer\n```\n\n#### profile with web_identity_token_file\n\n```ini\n[default]\nweb_identity_token_file=/temp/token\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\n```\n\nYou can specify another profile(`second`) whose credentials are used to assume the role by the\n`role_arn` setting in this profile(`first`).\n\n```ini\n[second]\nweb_identity_token_file=/temp/token\nrole_arn=arn:aws:iam::123456789012:role/example-role-2\n\n[first]\nsource_profile=second\nrole_arn=arn:aws:iam::123456789012:role/example-role\n```\n\n#### profile with sso credentials\n\nSee [`fromSSO()`](#fromsso) for more information\n\n## `fromEnv()`\n\n- Not available in browser & native apps\n\n```javascript\nimport { fromEnv } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromEnv } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  credentials: fromEnv(),\n});\n```\n\n`fromEnv` returns a `AwsCredentialIdentityProvider` function, that reads credentials from the following\nenvironment variables:\n\n- `AWS_ACCESS_KEY_ID` - The access key for your AWS account.\n- `AWS_SECRET_ACCESS_KEY` - The secret key for your AWS account.\n- `AWS_SESSION_TOKEN` - The session key for your AWS account. This is only needed when you are using\n  temporary credentials.\n- `AWS_CREDENTIAL_EXPIRATION` - The expiration time of the credentials contained in the environment\n  variables described above. This value must be in a format compatible with the\n  [ISO-8601 standard][iso8601_standard] and is only needed when you are using temporary credentials.\n\nIf either the `AWS_ACCESS_KEY_ID` or `AWS_SECRET_ACCESS_KEY` environment variable is not set or\ncontains a falsy value, the promise returned by the `fromEnv` function will be rejected.\n\n## `fromProcess()`\n\n- Not available in browsers & native apps\n\n```javascript\nimport { fromProcess } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromProcess } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  credentials: fromProcess({\n    // Optional. The configuration profile to use. If not specified, the provider will use the value\n    // in the `AWS_PROFILE` environment variable or a default of `default`.\n    profile: \"profile\",\n    // Optional. The path to the shared credentials file. If not specified, the provider will use\n    // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of\n    // `~/.aws/credentials`.\n    filepath: \"~/.aws/credentials\",\n    // Optional. The path to the shared config file. If not specified, the provider will use the\n    // value in the `AWS_CONFIG_FILE` environment variable or a default of `~/.aws/config`.\n    configFilepath: \"~/.aws/config\",\n  }),\n});\n```\n\n`fromSharedConfigFiles` creates a `AwsCredentialIdentityProvider` functions that executes a given process and\nattempt to read its standard output to receive a JSON payload containing the credentials. The\nprocess command is read from a shared credentials file at `~/.aws/credentials` and a shared\nconfiguration file at `~/.aws/config`. Both files are expected to be INI formatted with section\nnames corresponding to profiles. Sections in the credentials file are treated as profile names,\nwhereas profile sections in the config file must have the format of`[profile profile-name]`, except\nfor the default profile. Please see the [sample files](#sample-files-1) below for examples of\nwell-formed configuration and credentials files.\n\nProfiles that appear in both files will not be merged, and the version that appears in the\ncredentials file will be given precedence over the profile found in the config file.\n\n### Sample files\n\n#### `~/.aws/credentials`\n\n```ini\n[default]\ncredential_process = /usr/local/bin/awscreds\n\n[dev]\ncredential_process = /usr/local/bin/awscreds dev\n```\n\n#### `~/.aws/config`\n\n```ini\n[default]\ncredential_process = /usr/local/bin/awscreds\n\n[profile dev]\ncredential_process = /usr/local/bin/awscreds dev\n```\n\n## `fromTokenFile()`\n\n- Uses `@aws-sdk/client-sts`\n- Not available in browsers & native apps\n\nThe function `fromTokenFile` returns `AwsCredentialIdentityProvider` that reads credentials as follows:\n\n- Reads file location of where the OIDC token is stored from either provided option\n  `webIdentityTokenFile` or environment variable `AWS_WEB_IDENTITY_TOKEN_FILE`.\n- Reads IAM role wanting to be assumed from either provided option `roleArn` or environment\n  variable `AWS_ROLE_ARN`.\n- Reads optional role session name to be used to distinguish sessions from provided option\n  `roleSessionName` or environment variable `AWS_ROLE_SESSION_NAME`. If session name is not defined,\n  it comes up with a role session name.\n- Reads OIDC token from file on disk.\n- Calls sts:AssumeRoleWithWebIdentity via `roleAssumerWithWebIdentity` option to get credentials.\n\n| **Configuration Key** | **Environment Variable**    | **Required** | **Description**                                   |\n| --------------------- | --------------------------- | ------------ | ------------------------------------------------- |\n| webIdentityTokenFile  | AWS_WEB_IDENTITY_TOKEN_FILE | true         | File location of where the `OIDC` token is stored |\n| roleArn               | AWS_ROLE_ARN                | true         | The IAM role wanting to be assumed                |\n| roleSessionName       | AWS_ROLE_SESSION_NAME       | false        | The IAM session name used to distinguish sessions |\n\n```javascript\nimport { fromTokenFile } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromTokenFile } = require(\"@aws-sdk/credential-providers\"); // CommonJS import\n\nconst client = new FooClient({\n  credentials: fromTokenFile({\n    // Optional. STS client config to make the assume role request.\n    clientConfig: { region }\n  });\n});\n```\n\n## `fromSSO()`\n\n- Uses `@aws-sdk/client-sso` & `@aws-sdk/client-sso-oidc`\n- Not available in browsers & native apps\n\n> This credential provider **ONLY** supports profiles using the SSO credential. If you have a\n> profile that assumes a role which derived from the SSO credential, you should use the\n> [`fromIni()`](#fromini), or `@aws-sdk/credential-provider-node` package.\n\n`fromSSO`, that creates `AwsCredentialIdentityProvider` functions that read from the _resolved_ access token\nfrom local disk then requests temporary AWS credentials. For guidance on the AWS Single Sign-On\nservice, please refer to [AWS's Single Sign-On documentation][sso_api].\n\nYou can create the `AwsCredentialIdentityProvider` functions using the inline SSO parameters(`ssoStartUrl`,\n`ssoAccountId`, `ssoRegion`, `ssoRoleName`) or load them from\n[AWS SDKs and Tools shared configuration and credentials files][shared_config_files].\nProfiles in the `credentials` file are given precedence over profiles in the `config` file.\n\nThis credential provider is intended for use with the AWS SDK for Node.js.\n\n### Supported configuration\n\nYou may customize how credentials are resolved by providing an options hash to the `fromSSO` factory\nfunction. You can either load the SSO config from shared INI credential files, or specify the\n`ssoStartUrl`, `ssoAccountId`, `ssoRegion`, and `ssoRoleName` directly from the code.\n\n```javascript\nimport { fromSSO } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromSSO } = require(\"@aws-sdk/credential-providers\") // CommonJS import\n\nconst client = new FooClient({\n  credentials: fromSSO({\n    // Optional. The configuration profile to use. If not specified, the provider will use the value\n    // in the `AWS_PROFILE` environment variable or `default` by default.\n    profile: \"my-sso-profile\",\n    // Optional. The path to the shared credentials file. If not specified, the provider will use\n    // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of\n    // `~/.aws/credentials`.\n    filepath: \"~/.aws/credentials\",\n    // Optional. The path to the shared config file. If not specified, the provider will use the\n    // value in the `AWS_CONFIG_FILE` environment variable or a default of `~/.aws/config`.\n    configFilepath: \"~/.aws/config\",\n    // Optional. The URL to the AWS SSO service. Required if any of the `sso*` options(except for\n    // `ssoClient`) is provided.\n    ssoStartUrl: \"https://d-abc123.awsapps.com/start\",\n    // Optional. The ID of the AWS account to use for temporary credentials. Required if any of the\n    // `sso*` options(except for `ssoClient`) is provided.\n    ssoAccountId: \"1234567890\",\n    // Optional. The AWS region to use for temporary credentials. Required if any of the `sso*`\n    // options(except for `ssoClient`) is provided.\n    ssoRegion: \"us-east-1\",\n    // Optional. The name of the AWS role to assume. Required if any of the `sso*` options(except\n    // for `ssoClient`) is provided.\n    ssoRoleName: \"SampleRole\",\n    // Optional. Overwrite the configuration used construct the SSO service client. If not\n    // specified, a default SSO client will be created with the region specified in the profile\n    // `sso_region` entry.\n    clientConfig: { region },\n  }),\n});\n```\n\n### SSO Login with the AWS CLI\n\nThis credential provider relies on the [AWS CLI][cli_sso] to log into an AWS SSO session. Here's a\nbrief walk-through:\n\n1. Create a new AWS SSO enabled profile using the AWS CLI. It will ask you to login to your AWS SSO\n   account and prompt for the name of the profile:\n\n```console\n$ aws configure sso\n...\n...\nCLI profile name [123456789011_ReadOnly]: my-sso-profile<ENTER>\n```\n\n2. Configure your SDK client with the SSO credential provider:\n\n```javascript\n//...\nconst client = new FooClient({ credentials: fromSSO({ profile: \"my-sso-profile\" })});\n```\n\nAlternatively, the SSO credential provider is supported in shared INI credentials provider\n\n```javascript\n//...\nconst client = new FooClient({ credentials: fromIni({ profile: \"my-sso-profile\" })});\n```\n\n3. To log out from the current SSO session, use the AWS CLI:\n\n```console\n$ aws sso logout\nSuccessfully signed out of all SSO profiles.\n```\n\n### Sample files\n\nThis credential provider is only applicable if the profile specified in shared configuration and\ncredentials files contain ALL of the following entries.\n\n#### `~/.aws/credentials`\n\n```ini\n[sample-profile]\nsso_account_id = 012345678901\nsso_region = us-east-1\nsso_role_name = SampleRole\nsso_start_url = https://d-abc123.awsapps.com/start\n```\n\n#### `~/.aws/config`\n\n```ini\n[profile sample-profile]\nsso_account_id = 012345678901\nsso_region = us-east-1\nsso_role_name = SampleRole\nsso_start_url = https://d-abc123.awsapps.com/start\n```\n\n## `fromNodeProviderChain()`\n\n- May use `@aws-sdk/client-sts`, `@aws-sdk/client-sso`, etc. depending on\n  which link in the chain finally resolves credentials.\n- Not available in browsers & native apps\n\nThe credential provider used as default in the Node.js clients, but with default role assumers so\nyou don't need to import them from STS client and supply them manually. You normally don't need\nto use this explicitly in the client constructor. It is useful for utility functions requiring\ncredentials like S3 presigner, or RDS signer.\n\nThis credential provider will attempt to find credentials from the following sources (listed in\norder of precedence):\n\n- [Environment variables exposed via `process.env`](#fromenv)\n- [SSO credentials from token cache](#fromsso)\n- [Web identity token credentials](#fromtokenfile)\n- [Shared credentials and config ini files](#fromini)\n- [The EC2/ECS Instance Metadata Service](#fromcontainermetadata-and-frominstancemetadata)\n\nThis credential provider will invoke one provider at a time and only\ncontinue to the next if no credentials have been located. For example, if\nthe process finds values defined via the `AWS_ACCESS_KEY_ID` and\n`AWS_SECRET_ACCESS_KEY` environment variables, the files at\n`~/.aws/credentials` and `~/.aws/config` will not be read, nor will any\nmessages be sent to the Instance Metadata Service\n\n```js\nimport { fromNodeProviderChain } from \"@aws-sdk/credential-providers\"; // ES6 import\n// const { fromNodeProviderChain } = require(\"@aws-sdk/credential-providers\") // CommonJS import\nconst credentialProvider = fromNodeProviderChain({\n  //...any input of fromEnv(), fromSSO(), fromTokenFile(), fromIni(),\n  // fromProcess(), fromInstanceMetadata(), fromContainerMetadata()\n  // Optional. Custom STS client configurations overriding the default ones.\n  clientConfig: { region },\n});\n```\n\n## Add Custom Headers to STS assume-role calls\n\nYou can specify the plugins--groups of middleware, to inject to the STS client.\nFor example, you can inject custom headers to each STS assume-role calls. It's\navailable in [`fromTemporaryCredentials()`](#fromtemporarycredentials),\n[`fromWebToken()`](#fromwebtoken), [`fromTokenFile()`](#fromtokenfile), [`fromIni()`](#fromini).\n\nCode example:\n\n```javascript\nconst addConfusedDeputyMiddleware = (next) => (args) => {\n  args.request.headers[\"x-amz-source-account\"] = account;\n  args.request.headers[\"x-amz-source-arn\"] = sourceArn;\n  return next(args);\n};\nconst confusedDeputyPlugin = {\n  applyToStack: (stack) => {\n    stack.add(addConfusedDeputyMiddleware, { step: \"finalizeRequest\" });\n  },\n};\nconst provider = fromTemporaryCredentials({\n  // Required. Options passed to STS AssumeRole operation.\n  params: {\n    RoleArn: \"arn:aws:iam::1234567890:role/Role\",\n  },\n  clientPlugins: [confusedDeputyPlugin],\n});\n```\n\n[getcredentialsforidentity_api]: https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html\n[getid_api]: https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetId.html\n[assumerole_api]: https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html\n[assumerolewithwebidentity_api]: https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html\n[iam_roles_for_tasks]: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html\n[iam_roles_for_ec2]: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html\n[config_instance_metadata]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html\n[iso8601_standard]: https://en.wikipedia.org/wiki/ISO_8601\n[sso_api]: https://aws.amazon.com/single-sign-on/\n[shared_config_files]: https://docs.aws.amazon.com/credref/latest/refdocs/creds-config-files.html\n[cli_sso]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html#sso-configure-profile\n","publish_time":1696275240590,"maintainers":[{"name":"mattsb42-aws","email":"bullocm@amazon.com"},{"name":"kuhe","email":"george.jing.fu+npm@gmail.com"},{"name":"amzn-oss","email":"osa-3p@amazon.com"},{"name":"aws-sdk-bot","email":"aws-sdk-js-automation@amazon.com"},{"name":"trivikr-aws","email":"trivikr@amazon.com"}],"_cnpm_publish_time":1696275240590,"dist-tags":{"latest":"3.1163.0"}}