-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Updates CognitoIdentityCredentials to accept AWS.config options #1317
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
.changes/next-release/feature-CognitoIdentityCredentials-1f2c8c48.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "feature", | ||
"category": "CognitoIdentityCredentials", | ||
"description": "Adds `clientConfig` as an optional parameter to the `CognitoIdentityCredentials` constructor. This parameter can be used to pass in client configuration to the underlying `CognitoIdentity` service client." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
import {Credentials} from '../credentials'; | ||
import {AWSError} from '../error'; | ||
import {ConfigurationOptions} from '../config'; | ||
import CognitoIdentity = require('../../clients/cognitoidentity'); | ||
import STS = require('../../clients/sts'); | ||
|
||
export class CognitoIdentityCredentials extends Credentials { | ||
/** | ||
* Creates a new credentials object. | ||
*/ | ||
constructor(options?: CognitoIdentity.Types.GetIdInput|CognitoIdentity.Types.GetCredentialsForIdentityInput|CognitoIdentity.Types.GetOpenIdTokenInput|STS.Types.AssumeRoleWithWebIdentityRequest); | ||
/** | ||
* Refreshes credentials using AWS.CognitoIdentity.getCredentialsForIdentity(), or AWS.STS.assumeRoleWithWebIdentity(). | ||
*/ | ||
refresh(callback: (err: AWSError) => void): void; | ||
/** | ||
* Clears the cached Cognito ID associated with the currently configured identity pool ID. | ||
*/ | ||
clearCachedId(): void; | ||
/** | ||
* The raw data response from the call to AWS.CognitoIdentity.getCredentialsForIdentity(), or AWS.STS.assumeRoleWithWebIdentity(). | ||
*/ | ||
data: CognitoIdentity.Types.GetCredentialsForIdentityResponse|STS.Types.AssumeRoleWithWebIdentityResponse; | ||
/** | ||
* The Cognito ID returned by the last call to AWS.CognitoIdentity.getOpenIdToken(). | ||
*/ | ||
identityId: string; | ||
/** | ||
* The map of params passed to AWS.CognitoIdentity.getId(), AWS.CognitoIdentity.getOpenIdToken(), and AWS.STS.assumeRoleWithWebIdentity(). | ||
*/ | ||
params: CognitoIdentity.Types.GetIdInput|CognitoIdentity.Types.GetOpenIdTokenInput|STS.Types.AssumeRoleWithWebIdentityRequest; | ||
} | ||
/** | ||
* Creates a new credentials object with optional configuration. | ||
*/ | ||
constructor(options: CognitoIdentityCredentials.CognitoIdentityOptions, clientConfig?: ConfigurationOptions); | ||
/** | ||
* Creates a new credentials object. | ||
*/ | ||
constructor(options?: CognitoIdentityCredentials.CognitoIdentityOptions); | ||
/** | ||
* Refreshes credentials using AWS.CognitoIdentity.getCredentialsForIdentity(), or AWS.STS.assumeRoleWithWebIdentity(). | ||
*/ | ||
refresh(callback: (err: AWSError) => void): void; | ||
/** | ||
* Clears the cached Cognito ID associated with the currently configured identity pool ID. | ||
*/ | ||
clearCachedId(): void; | ||
/** | ||
* The raw data response from the call to AWS.CognitoIdentity.getCredentialsForIdentity(), or AWS.STS.assumeRoleWithWebIdentity(). | ||
*/ | ||
data: CognitoIdentity.Types.GetCredentialsForIdentityResponse|STS.Types.AssumeRoleWithWebIdentityResponse; | ||
/** | ||
* The Cognito ID returned by the last call to AWS.CognitoIdentity.getOpenIdToken(). | ||
*/ | ||
identityId: string; | ||
/** | ||
* The map of params passed to AWS.CognitoIdentity.getId(), AWS.CognitoIdentity.getOpenIdToken(), and AWS.STS.assumeRoleWithWebIdentity(). | ||
*/ | ||
params: CognitoIdentity.Types.GetIdInput|CognitoIdentity.Types.GetOpenIdTokenInput|STS.Types.AssumeRoleWithWebIdentityRequest; | ||
} | ||
|
||
// Needed to expose interfaces on the class | ||
declare namespace CognitoIdentityCredentials { | ||
export type CognitoIdentityCredentialsInputs = CognitoIdentity.GetIdInput|CognitoIdentity.GetCredentialsForIdentityInput|CognitoIdentity.GetOpenIdTokenInput|STS.AssumeRoleWithWebIdentityRequest; | ||
export type CognitoIdentityOptions = CognitoIdentityCredentialsInputs & {LoginId?: string} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {CognitoIdentityCredentials} from '../lib/credentials/cognito_identity_credentials'; | ||
|
||
const creds1 = new CognitoIdentityCredentials(); | ||
const creds2 = new CognitoIdentityCredentials({ | ||
IdentityPoolId: 'fake' | ||
}); | ||
const creds3: CognitoIdentityCredentials = new CognitoIdentityCredentials({ | ||
IdentityId: 'id' | ||
}); | ||
|
||
const creds4: CognitoIdentityCredentials = new CognitoIdentityCredentials({ | ||
IdentityId: 'id', | ||
RoleArn: 'arn' | ||
}); | ||
|
||
const credOptions: CognitoIdentityCredentials.CognitoIdentityOptions = { | ||
IdentityId: 'id', | ||
Logins: { | ||
'graph.facebook.com': 'FBTOKEN', | ||
'www.amazon.com': 'AMAZONTOKEN', | ||
'accounts.google.com': 'GOOGLETOKEN', | ||
'api.twitter.com': 'TWITTERTOKEN', | ||
'www.digits.com': 'DIGITSTOKEN' | ||
}, | ||
LoginId: 'example@gmail.com' | ||
} | ||
|
||
const creds5: CognitoIdentityCredentials = new CognitoIdentityCredentials(credOptions); | ||
|
||
// test client config | ||
const creds6: CognitoIdentityCredentials = new CognitoIdentityCredentials(credOptions, { | ||
httpOptions: { | ||
timeout: 50 | ||
}, | ||
region: 'us-west-2' | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the client config be passed to STS, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went back and forth on that. Since
STS
uses a global endpoint, it's fine if the region the user passes in isn't us-east-1.I would probably also have to update WebIdentityCredentials to accept client config, since it calls STS as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other configuration options that customers might want to control (e.g., timeouts, retries, http agents, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Sorry, I wasn't clear in my response. I was initially worried that a different region would cause an issue with STS, but discovered that's not the case. I'll update the PR to pass config to STS (and likewise to WebIdentityCredentials as well).