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

Add support for the customRoleArn (#1125) #7631

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class AuthClass {
identityPoolRegion,
clientMetadata,
endpoint,
customRoleArn,
} = this._config;

if (!this._config.storage) {
Expand Down Expand Up @@ -195,6 +196,7 @@ export class AuthClass {
identityPoolId,
refreshHandlers,
storage: this._storage,
customRoleArn,
});

// initiailize cognitoauth client if hosted ui options provided
Expand Down
2 changes: 2 additions & 0 deletions packages/auth/src/types/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ICookieStorageData,
ICognitoStorage,
CognitoUserAttribute,
CognitoIdToken,
} from 'amazon-cognito-identity-js';

/**
Expand Down Expand Up @@ -51,6 +52,7 @@ export interface AuthOptions {
identityPoolRegion?: string;
clientMetadata?: any;
endpoint?: string;
customRoleArn?: (token : CognitoIdToken | string) => string,
}

export enum CognitoHostedUIIdentityProvider {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/Credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export class CredentialsClass {
const logins = {};
logins[domain] = token;

const { identityPoolId, region } = this._config;
const { identityPoolId, region, customRoleArn } = this._config;
if (!identityPoolId) {
logger.debug('No Cognito Federated Identity pool provided');
return Promise.reject('No Cognito Federated Identity pool provided');
Expand All @@ -385,13 +385,15 @@ export class CredentialsClass {
identityId: identity_id,
logins,
client: cognitoClient,
customRoleArn: customRoleArn && customRoleArn(token),
};
credentials = fromCognitoIdentity(cognitoIdentityParams)();
} else {
const cognitoIdentityParams: FromCognitoIdentityPoolParameters = {
logins,
identityPoolId,
client: cognitoClient,
customRoleArn: customRoleArn && customRoleArn(token),
};
credentials = fromCognitoIdentityPool(cognitoIdentityParams)();
}
Expand All @@ -401,7 +403,7 @@ export class CredentialsClass {
private _setCredentialsFromSession(session): Promise<ICredentials> {
logger.debug('set credentials from session');
const idToken = session.getIdToken().getJwtToken();
const { region, userPoolId, identityPoolId } = this._config;
const { region, userPoolId, identityPoolId, customRoleArn } = this._config;
if (!identityPoolId) {
logger.debug('No Cognito Federated Identity pool provided');
return Promise.reject('No Cognito Federated Identity pool provided');
Expand Down Expand Up @@ -440,6 +442,7 @@ export class CredentialsClass {
client: cognitoClient,
logins,
identityId: IdentityId,
customRoleArn: customRoleArn && customRoleArn(idToken)
};

const credentialsFromCognitoIdentity = fromCognitoIdentity(
Expand Down