insomnia-plugin-aws-amplify 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/app.js +63 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,11 +5,48 @@
|
|
|
5
5
|
[Insomnia](https://insomnia.rest) plugin for signing in via AWS Amplify
|
|
6
6
|
|
|
7
7
|
**Key Features**
|
|
8
|
+
|
|
8
9
|
- Environment configuration GUI to input Amplify credentials.
|
|
9
10
|
- Automatic token caching and flexible expiry options.
|
|
10
11
|
- Customisable return properties (Access Token, ID Token, User ID, Auth ID).
|
|
11
12
|
- Multiple user pool support across environments.
|
|
13
|
+
- Two authentication methods: AWS Amplify with USER_SRP_AUTH or Cognito Identity Provider with ADMIN_USER_PASSWORD_AUTH
|
|
12
14
|
|
|
13
15
|
## Installation
|
|
16
|
+
|
|
14
17
|
1. Open Insomnia and go to plugin settings.
|
|
15
18
|
2. Add `insomnia-plugin-aws-amplify`.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### AWS Amplify Provider (Default)
|
|
23
|
+
|
|
24
|
+
Uses client-side authentication flow. No AWS credentials required.
|
|
25
|
+
|
|
26
|
+
**Required fields:**
|
|
27
|
+
|
|
28
|
+
- username
|
|
29
|
+
- password
|
|
30
|
+
- region (e.g., `us-east-1`)
|
|
31
|
+
- userPoolId (e.g., `us-east-1_XXXXXXXXX`)
|
|
32
|
+
- clientId
|
|
33
|
+
|
|
34
|
+
### Cognito Identity Provider
|
|
35
|
+
|
|
36
|
+
Uses server-side AdminInitiateAuth flow. Retrieves AWS credentials from your local AWS CLI configuration.
|
|
37
|
+
|
|
38
|
+
**Required fields:**
|
|
39
|
+
|
|
40
|
+
- username
|
|
41
|
+
- password
|
|
42
|
+
- region (e.g., `us-east-1`)
|
|
43
|
+
- userPoolId (e.g., `us-east-1_XXXXXXXXX`)
|
|
44
|
+
- clientId
|
|
45
|
+
- **awsProfile**: AWS profile name (e.g., `staging`) - only shown when "Cognito Identity Provider" is selected
|
|
46
|
+
|
|
47
|
+
**Notes**:
|
|
48
|
+
|
|
49
|
+
- The plugin uses the AWS CLI to retrieve credentials, so you must have:
|
|
50
|
+
1. AWS CLI installed and configured
|
|
51
|
+
2. Valid SSO session (run `aws sso login --profile <profile-name>`)
|
|
52
|
+
- Your AWS profile/role must have permission to call `cognito-idp:AdminInitiateAuth`:
|
package/app.js
CHANGED
|
@@ -242238,6 +242238,7 @@ __export(app_exports, {
|
|
|
242238
242238
|
module.exports = __toCommonJS(app_exports);
|
|
242239
242239
|
|
|
242240
242240
|
// src/modules/auth/index.ts
|
|
242241
|
+
var import_node_child_process = require("child_process");
|
|
242241
242242
|
var import_client_cognito_identity_provider = __toESM(require_dist_cjs59());
|
|
242242
242243
|
var import_aws_amplify = __toESM(require_lib20());
|
|
242243
242244
|
async function loginUser(username, password, region, userPoolId, clientId) {
|
|
@@ -242264,8 +242265,43 @@ async function loginUser(username, password, region, userPoolId, clientId) {
|
|
|
242264
242265
|
accessToken
|
|
242265
242266
|
};
|
|
242266
242267
|
}
|
|
242267
|
-
async function loginUserViaCognito(username, password, region, userPoolId, clientId) {
|
|
242268
|
-
const
|
|
242268
|
+
async function loginUserViaCognito(username, password, region, userPoolId, clientId, awsProfile) {
|
|
242269
|
+
const profileName = (awsProfile == null ? void 0 : awsProfile.trim()) || "";
|
|
242270
|
+
if (!profileName) {
|
|
242271
|
+
throw new Error(
|
|
242272
|
+
'AWS Profile is required for Cognito Identity Provider. Please specify your AWS profile name (e.g., "staging").'
|
|
242273
|
+
);
|
|
242274
|
+
}
|
|
242275
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(profileName)) {
|
|
242276
|
+
throw new Error(
|
|
242277
|
+
`Invalid AWS profile name: "${profileName}". Profile names can only contain letters, numbers, hyphens, and underscores.`
|
|
242278
|
+
);
|
|
242279
|
+
}
|
|
242280
|
+
let credentials;
|
|
242281
|
+
try {
|
|
242282
|
+
const output = (0, import_node_child_process.execSync)(
|
|
242283
|
+
`aws configure export-credentials --profile ${profileName} --format process`,
|
|
242284
|
+
{
|
|
242285
|
+
encoding: "utf-8",
|
|
242286
|
+
timeout: 5e3
|
|
242287
|
+
// 5 seconds timeout
|
|
242288
|
+
}
|
|
242289
|
+
);
|
|
242290
|
+
const creds = JSON.parse(output);
|
|
242291
|
+
credentials = {
|
|
242292
|
+
accessKeyId: creds.AccessKeyId,
|
|
242293
|
+
secretAccessKey: creds.SecretAccessKey,
|
|
242294
|
+
sessionToken: creds.SessionToken
|
|
242295
|
+
};
|
|
242296
|
+
} catch (error2) {
|
|
242297
|
+
throw new Error(
|
|
242298
|
+
`Failed to load AWS credentials for profile "${profileName}". Make sure you have run 'aws sso login --profile ${profileName}' and have valid credentials. Error: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
242299
|
+
);
|
|
242300
|
+
}
|
|
242301
|
+
const client = new import_client_cognito_identity_provider.CognitoIdentityProviderClient({
|
|
242302
|
+
region,
|
|
242303
|
+
credentials
|
|
242304
|
+
});
|
|
242269
242305
|
const command = new import_client_cognito_identity_provider.AdminInitiateAuthCommand({
|
|
242270
242306
|
AuthFlow: "ADMIN_USER_PASSWORD_AUTH",
|
|
242271
242307
|
UserPoolId: userPoolId,
|
|
@@ -242277,7 +242313,7 @@ async function loginUserViaCognito(username, password, region, userPoolId, clien
|
|
|
242277
242313
|
});
|
|
242278
242314
|
const response = await client.send(command);
|
|
242279
242315
|
const authResult = response.AuthenticationResult;
|
|
242280
|
-
if (!authResult
|
|
242316
|
+
if (!(authResult == null ? void 0 : authResult.IdToken) || !authResult.AccessToken) {
|
|
242281
242317
|
throw new Error(
|
|
242282
242318
|
`Invalid auth response: ${JSON.stringify(response, null, 2)}`
|
|
242283
242319
|
);
|
|
@@ -242388,6 +242424,7 @@ var root = async (context, ...args) => {
|
|
|
242388
242424
|
userPoolId,
|
|
242389
242425
|
clientId,
|
|
242390
242426
|
provider,
|
|
242427
|
+
awsProfile,
|
|
242391
242428
|
returnValue
|
|
242392
242429
|
] = args;
|
|
242393
242430
|
const inputs = { username, password, region, userPoolId, clientId };
|
|
@@ -242402,7 +242439,8 @@ var root = async (context, ...args) => {
|
|
|
242402
242439
|
region,
|
|
242403
242440
|
userPoolId,
|
|
242404
242441
|
clientId,
|
|
242405
|
-
provider
|
|
242442
|
+
provider,
|
|
242443
|
+
awsProfile
|
|
242406
242444
|
});
|
|
242407
242445
|
const authStorePool = await getAuthPool(context.store, userPoolId);
|
|
242408
242446
|
if (!authStorePool) {
|
|
@@ -242428,14 +242466,23 @@ var authenticate = async (context) => {
|
|
|
242428
242466
|
if (!inputStore) {
|
|
242429
242467
|
throw Error("Input credentials not found in cache");
|
|
242430
242468
|
}
|
|
242431
|
-
const {
|
|
242469
|
+
const {
|
|
242470
|
+
username,
|
|
242471
|
+
password,
|
|
242472
|
+
region,
|
|
242473
|
+
userPoolId,
|
|
242474
|
+
clientId,
|
|
242475
|
+
provider,
|
|
242476
|
+
awsProfile
|
|
242477
|
+
} = inputStore;
|
|
242432
242478
|
try {
|
|
242433
242479
|
const loginResponse = provider === "amplify" ? await loginUser(username, password, region, userPoolId, clientId) : await loginUserViaCognito(
|
|
242434
242480
|
username,
|
|
242435
242481
|
password,
|
|
242436
242482
|
region,
|
|
242437
242483
|
userPoolId,
|
|
242438
|
-
clientId
|
|
242484
|
+
clientId,
|
|
242485
|
+
awsProfile
|
|
242439
242486
|
);
|
|
242440
242487
|
const ONE_HOUR_MS = 1e3 * 60 * 60;
|
|
242441
242488
|
const expiresAt = (/* @__PURE__ */ new Date()).getTime() + ONE_HOUR_MS;
|
|
@@ -242524,6 +242571,16 @@ var rootTemplate = [
|
|
|
242524
242571
|
}
|
|
242525
242572
|
]
|
|
242526
242573
|
},
|
|
242574
|
+
{
|
|
242575
|
+
displayName: "awsProfile",
|
|
242576
|
+
type: "string",
|
|
242577
|
+
defaultValue: "staging",
|
|
242578
|
+
help: 'Run "aws sso login --profile <name>" first, and use the same profile name here.',
|
|
242579
|
+
hide: (args) => {
|
|
242580
|
+
const providerArg = args[5];
|
|
242581
|
+
return (providerArg == null ? void 0 : providerArg.value) !== "cognito";
|
|
242582
|
+
}
|
|
242583
|
+
},
|
|
242527
242584
|
{
|
|
242528
242585
|
displayName: "returnValue",
|
|
242529
242586
|
type: "enum",
|