Skip to content

Commit 0e75ebf

Browse files
author
Austin Johnson
committed
Consolidate login code on Vue side to one location
1 parent 7c2148f commit 0e75ebf

File tree

3 files changed

+3
-66
lines changed

3 files changed

+3
-66
lines changed

build/Makefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,8 @@ upload-templates: $(TEMPLATES) | $(OUT)
3737
aws s3 sync --acl public-read --exclude "*" --include "*.yaml" \
3838
"$(TEMPLATES_DIR)" "s3://$(BOOTSTRAP_BUCKET_PATH)/templates/" \
3939
| tee "$(OUT)/$(@)"
40-
aws s3 cp "$(TEMPLATES_DIR)"/layers.zip \
41-
"s3://${BOOTSTRAP_BUCKET_PATH}/layers.zip"
4240
@echo "[INFO] master template: https://s3.amazonaws.com/$(BOOTSTRAP_BUCKET_PATH)/templates/master.yaml"
4341

44-
LAMBDA_LAYER_ZIP := $(TEMPLATES_DIR)/layers.zip
45-
46-
upload-layers:
47-
@echo "[INFO] Uploading lambda layer"
48-
aws s3 cp --acl public-read "$(LAMBDA_LAYER_ZIP)" "s3://${BOOTSTRAP_BUCKET_PATH}/layers.zip"
49-
5042
# cfn custom resource lambda files are found under this directory
5143
CUSTOM_RESOURCES_DIR := $(TEMPLATES_DIR)/custom-resources
5244

lex-web-ui/src/lex-web-ui.js

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ License for the specific language governing permissions and limitations under th
1818
* Exports Loader as the plugin constructor
1919
* and Store as store that can be used with Vuex.Store()
2020
*/
21-
import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers';
22-
import { CognitoIdentityClient, GetIdCommand, GetCredentialsForIdentityCommand } from '@aws-sdk/client-cognito-identity';
2321
import { LexRuntimeServiceClient } from '@aws-sdk/client-lex-runtime-service';
2422
import { LexRuntimeV2Client } from '@aws-sdk/client-lex-runtime-v2';
2523
import { PollyClient } from '@aws-sdk/client-polly';
@@ -161,7 +159,8 @@ export class Loader {
161159
const mergedConfig = mergeConfig(defaultConfig, config);
162160
let credentials;
163161
if (mergedConfig.cognito.poolId != '' || localStorage.getItem('poolId')) {
164-
credentials = this.getCredentials(mergedConfig).then((creds) => {
162+
credentials = this.store.dispatch('getCredentials', mergeConfig).then((creds) => {
163+
//credentials = this.getCredentials(mergedConfig).then((creds) => {
165164
return creds;
166165
});
167166
}
@@ -185,56 +184,6 @@ export class Loader {
185184
});
186185
this.app = app;
187186
}
188-
189-
async getCredentials(context) {
190-
const region = context.region || context.cognito.poolId.split(':')[0] || 'us-east-1';
191-
const poolId = context.cognito.poolId || localStorage.getItem('poolId');
192-
const appUserPoolName = context.cognito.appUserPoolName || localStorage.getItem('appUserPoolName');
193-
const poolName = `cognito-idp.${region}.amazonaws.com/${appUserPoolName}`;
194-
const appUserPoolClientId = context.cognito.appUserPoolClientId || localStorage.getItem('appUserPoolClientId')
195-
const idtoken = localStorage.getItem(`${appUserPoolClientId}idtokenjwt`);
196-
let logins;
197-
if (idtoken) {
198-
logins = {};
199-
logins[poolName] = idtoken;
200-
const client = new CognitoIdentityClient({ region });
201-
const getIdentityId = new GetIdCommand({
202-
IdentityPoolId: poolId,
203-
Logins: logins ? logins : {}
204-
})
205-
let identityId, getCreds;
206-
207-
try {
208-
await client.send(getIdentityId)
209-
.then((res) => {
210-
identityId = res.IdentityId;
211-
getCreds = new GetCredentialsForIdentityCommand({
212-
IdentityId: identityId,
213-
Logins: logins ? logins : {}
214-
})
215-
})
216-
const res = await client.send(getCreds);
217-
const creds = res.Credentials;
218-
const credentials = {
219-
accessKeyId: creds.AccessKeyId,
220-
identityId,
221-
secretAccessKey: creds.SecretKey,
222-
sessionToken: creds.SessionToken,
223-
expiration: creds.Expiration,
224-
};
225-
return credentials;
226-
} catch (err) {
227-
console.log(err)
228-
}
229-
} else {
230-
const credentialProvider = fromCognitoIdentityPool({
231-
identityPoolId: poolId,
232-
clientConfig: { region },
233-
})
234-
const credentials = credentialProvider()
235-
return credentials
236-
}
237-
}
238187
}
239188

240189
// comment out for prod build

src/lex-web-ui-loader/js/defaults/dependencies.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ export const dependenciesFullPage = {
2424
name: 'Loader',
2525
url: './initiate-loader.js',
2626
},
27-
{
28-
name: 'AWS',
29-
url: './aws-sdk-2.903.0.js',
30-
canUseMin: true,
31-
},
3227
{
3328
name: 'Vue',
3429
url: './3.3.10_dist_vue.global.prod.js',
@@ -79,4 +74,5 @@ export const dependenciesIframe = {
7974
url: './lex-web-ui-loader.css',
8075
},
8176
],
77+
script: []
8278
};

0 commit comments

Comments
 (0)