Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into improve-cdk-detecti…
Browse files Browse the repository at this point in the history
…on-logic
  • Loading branch information
sobolk committed May 31, 2024
2 parents 634f064 + f204baa commit 6f8742d
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-needles-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/client-config': patch
---

fix: add oauth client config for legacy mobile config
12 changes: 12 additions & 0 deletions .changeset/light-pets-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@aws-amplify/integration-tests': patch
'@aws-amplify/backend-function': patch
'@aws-amplify/backend-storage': patch
'@aws-amplify/client-config': patch
'@aws-amplify/platform-core': patch
'@aws-amplify/backend-data': patch
'@aws-amplify/backend': patch
'@aws-amplify/backend-cli': patch
---

chore: disambiguate url imports and import from node:url explicitly
5 changes: 5 additions & 0 deletions .changeset/olive-boxes-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/client-config': patch
---

fix: use correct auth mode in data config for legacy mobile client config
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/backend-data/src/convert_js_resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AmplifyData } from '@aws-amplify/data-construct';
import { CfnFunctionConfiguration, CfnResolver } from 'aws-cdk-lib/aws-appsync';
import { JsResolver } from '@aws-amplify/data-schema-types';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { Asset } from 'aws-cdk-lib/aws-s3-assets';
import { resolveEntryPath } from './resolve_entry_path.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/backend-function/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from '@aws-amplify/backend-output-schemas';
import { FunctionEnvironmentTypeGenerator } from './function_env_type_generator.js';
import { AttributionMetadataStorage } from '@aws-amplify/backend-output-storage';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { AmplifyUserError, TagName } from '@aws-amplify/platform-core';

const functionStackType = 'function-Lambda';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-storage/src/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
AttributionMetadataStorage,
StackMetadataBackendOutputStorageStrategy,
} from '@aws-amplify/backend-output-storage';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { IFunction } from 'aws-cdk-lib/aws-lambda';
import { S3EventSourceV2 } from 'aws-cdk-lib/aws-lambda-event-sources';

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/backend_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { createDefaultStack } from './default_stack_factory.js';
import { getBackendIdentifier } from './backend_identifier.js';
import { platformOutputKey } from '@aws-amplify/backend-output-schemas';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { Backend, DefineBackendProps } from './backend.js';
import { AmplifyBranchLinkerConstruct } from './engine/branch-linker/branch_linker_construct.js';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as iam from 'aws-cdk-lib/aws-iam';
import * as path from 'path';
import { Runtime as LambdaRuntime } from 'aws-cdk-lib/aws-lambda';
import { Provider } from 'aws-cdk-lib/custom-resources';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { BackendIdentifier } from '@aws-amplify/plugin-types';
import { ParameterPathConversions } from '@aws-amplify/platform-core';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Construct } from 'constructs';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { Runtime as LambdaRuntime } from 'aws-cdk-lib/aws-lambda';
import { CustomResource, Duration } from 'aws-cdk-lib';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import path from 'path';
import { Provider } from 'aws-cdk-lib/custom-resources';
import { AmplifyBranchLinkerCustomResourceProps } from './lambda/branch_linker_types.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/engine/nested_stack_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NestedStack, Stack } from 'aws-cdk-lib';
import { AttributionMetadataStorage } from '@aws-amplify/backend-output-storage';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';

/**
* Vends stacks for a resource grouping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommandModule } from 'yargs';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import {
SandboxCommand,
SandboxCommandOptionsKebabCase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ export type ClientConfigMobileAppsyncAuth = {
ClientDatabasePrefix: string | undefined;
};

// Reference: https://github.com/aws-amplify/amplify-cli/blob/80a596498584d3f9bfeb0ffbde4a0d4256f971eb/packages/amplify-frontend-ios/lib/frontend-config-creator.js#L243-L255
// Note that AppClientSecret is not here since we don't collect it in Gen2
export type ClientConfigMobileAuthOAuthConfig = {
WebDomain: string | undefined;
Scopes: Array<string> | undefined;
SignInRedirectURI: string | undefined;
SignOutRedirectURI: string | undefined;
AppClientId: string | undefined;
};

export type ClientConfigMobileAuth = {
plugins: {
awsCognitoAuthPlugin: {
Expand Down Expand Up @@ -64,6 +74,7 @@ export type ClientConfigMobileAuth = {
signupAttributes: Array<string>;
usernameAttributes: Array<string>;
verificationMechanisms: Array<string>;
OAuth?: ClientConfigMobileAuthOAuthConfig;
};
};
AppSync?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ void describe('client config converter', () => {
],
aws_cognito_mfa_configuration: 'test_mfa_configuration',
aws_cognito_mfa_types: ['test_mfa_type_1', 'test_mfa_type_2'],

oauth: {
clientId: 'test_client_id',
domain: 'test_domain',
scope: ['test_scope_1', 'test_scope_2'],
redirectSignIn: 'test_redirect_sign_in',
redirectSignOut: 'test_redirect_sign_out',
},
};
const expectedMobileConfig: ClientConfigMobile = {
UserAgent: expectedUserAgent,
Expand Down Expand Up @@ -82,6 +90,13 @@ void describe('client config converter', () => {
'test_verification_mechanism_1',
'test_verification_mechanism_2',
],
OAuth: {
WebDomain: 'test_domain',
AppClientId: 'test_client_id',
Scopes: ['test_scope_1', 'test_scope_2'],
SignInRedirectURI: 'test_redirect_sign_in',
SignOutRedirectURI: 'test_redirect_sign_out',
},
},
},
},
Expand Down Expand Up @@ -185,14 +200,14 @@ void describe('client config converter', () => {
data_AWS_IAM: {
ApiUrl: 'https://test_api_endpoint.amazon.com',
Region: 'test_app_sync_region',
AuthMode: 'API_KEY',
AuthMode: 'AWS_IAM',
ApiKey: 'test_api_key',
ClientDatabasePrefix: 'data_AWS_IAM',
},
data_AMAZON_COGNITO_USER_POOLS: {
ApiUrl: 'https://test_api_endpoint.amazon.com',
Region: 'test_app_sync_region',
AuthMode: 'API_KEY',
AuthMode: 'AMAZON_COGNITO_USER_POOLS',
ApiKey: 'test_api_key',
ClientDatabasePrefix: 'data_AMAZON_COGNITO_USER_POOLS',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ export class ClientConfigMobileConverter {
},
},
};
if (clientConfig.oauth) {
authConfig.plugins.awsCognitoAuthPlugin.Auth.Default.OAuth = {
WebDomain: clientConfig.oauth.domain,
Scopes: clientConfig.oauth.scope,
SignInRedirectURI: clientConfig.oauth.redirectSignIn,
SignOutRedirectURI: clientConfig.oauth.redirectSignOut,
AppClientId: clientConfig.oauth.clientId,
};
}
mobileConfig.auth = authConfig;
}

Expand Down Expand Up @@ -116,7 +125,7 @@ export class ClientConfigMobileConverter {
] = {
ApiUrl: clientConfig.aws_appsync_graphqlEndpoint,
Region: clientConfig.aws_appsync_region,
AuthMode: clientConfig.aws_appsync_authenticationType,
AuthMode: additionalAuthenticationType,
ApiKey: clientConfig.aws_appsync_apiKey,
ClientDatabasePrefix: `data_${additionalAuthenticationType}`,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/client-config/src/write_client_config_to_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './client-config-types/client_config.js';
import { getClientConfigPath } from './paths/index.js';
import { ClientConfigMobileConverter } from './client-config-writer/client_config_to_mobile_legacy_converter.js';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import * as fsp from 'fs/promises';
import { ClientConfigFormatterLegacy } from './client-config-writer/client_config_formatter_legacy.js';
import { ClientConfigFormatterDefault } from './client-config-writer/client_config_formatter_default.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/src/cdk_version_finder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fsp from 'fs/promises';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import semver from 'semver';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/src/setup_test_directory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync } from 'fs';
import fs from 'fs/promises';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';

/**
* Root test directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloudFormationClient } from '@aws-sdk/client-cloudformation';
import { e2eToolingClientConfig } from '../../e2e_tooling_client_config.js';
import { TestCdkProjectBase } from './test_cdk_project_base.js';
import { AuthTestCdkProjectCreator } from './auth_cdk_project.js';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import path from 'path';
import { DeployedResourcesFinder } from '../../find_deployed_resource.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BackendIdentifier } from '@aws-amplify/plugin-types';
import { createEmptyAmplifyProject } from './create_empty_amplify_project.js';
import { CloudFormationClient } from '@aws-sdk/client-cloudformation';
import { TestProjectBase, TestProjectUpdate } from './test_project_base.js';
import { fileURLToPath, pathToFileURL } from 'url';
import { fileURLToPath, pathToFileURL } from 'node:url';
import path from 'path';
import { TestProjectCreator } from './test_project_creator.js';
import { DeployedResourcesFinder } from '../find_deployed_resource.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';

/**
* Regex that pulls out the path from a stack trace line. Works for both unix and windows paths and cjs and esm loaders
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import url, { UrlWithStringQuery } from 'url';
import url, { UrlWithStringQuery } from 'node:url';
import { latestApiVersion } from './constants.js';

let cachedUrl: UrlWithStringQuery;
Expand Down

0 comments on commit 6f8742d

Please sign in to comment.