Skip to content

Commit 1146bbd

Browse files
authored
fix: add oauth client config for legacy mobile config (#1578)
* fix: add oauth client config for legacy mobile config * PR feedback updates
1 parent 530bf2c commit 1146bbd

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

.changeset/few-needles-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/client-config': patch
3+
---
4+
5+
fix: add oauth client config for legacy mobile config

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/client-config/src/client-config-types/mobile/client_config_mobile_types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ export type ClientConfigMobileAppsyncAuth = {
3232
ClientDatabasePrefix: string | undefined;
3333
};
3434

35+
// Reference: https://github.com/aws-amplify/amplify-cli/blob/80a596498584d3f9bfeb0ffbde4a0d4256f971eb/packages/amplify-frontend-ios/lib/frontend-config-creator.js#L243-L255
36+
// Note that AppClientSecret is not here since we don't collect it in Gen2
37+
export type ClientConfigMobileAuthOAuthConfig = {
38+
WebDomain: string | undefined;
39+
Scopes: Array<string> | undefined;
40+
SignInRedirectURI: string | undefined;
41+
SignOutRedirectURI: string | undefined;
42+
AppClientId: string | undefined;
43+
};
44+
3545
export type ClientConfigMobileAuth = {
3646
plugins: {
3747
awsCognitoAuthPlugin: {
@@ -64,6 +74,7 @@ export type ClientConfigMobileAuth = {
6474
signupAttributes: Array<string>;
6575
usernameAttributes: Array<string>;
6676
verificationMechanisms: Array<string>;
77+
OAuth?: ClientConfigMobileAuthOAuthConfig;
6778
};
6879
};
6980
AppSync?: {

packages/client-config/src/client-config-writer/client_config_to_mobile_legacy_converter.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ void describe('client config converter', () => {
3737
],
3838
aws_cognito_mfa_configuration: 'test_mfa_configuration',
3939
aws_cognito_mfa_types: ['test_mfa_type_1', 'test_mfa_type_2'],
40+
41+
oauth: {
42+
clientId: 'test_client_id',
43+
domain: 'test_domain',
44+
scope: ['test_scope_1', 'test_scope_2'],
45+
redirectSignIn: 'test_redirect_sign_in',
46+
redirectSignOut: 'test_redirect_sign_out',
47+
},
4048
};
4149
const expectedMobileConfig: ClientConfigMobile = {
4250
UserAgent: expectedUserAgent,
@@ -82,6 +90,13 @@ void describe('client config converter', () => {
8290
'test_verification_mechanism_1',
8391
'test_verification_mechanism_2',
8492
],
93+
OAuth: {
94+
WebDomain: 'test_domain',
95+
AppClientId: 'test_client_id',
96+
Scopes: ['test_scope_1', 'test_scope_2'],
97+
SignInRedirectURI: 'test_redirect_sign_in',
98+
SignOutRedirectURI: 'test_redirect_sign_out',
99+
},
85100
},
86101
},
87102
},

packages/client-config/src/client-config-writer/client_config_to_mobile_legacy_converter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ export class ClientConfigMobileConverter {
7474
},
7575
},
7676
};
77+
if (clientConfig.oauth) {
78+
authConfig.plugins.awsCognitoAuthPlugin.Auth.Default.OAuth = {
79+
WebDomain: clientConfig.oauth.domain,
80+
Scopes: clientConfig.oauth.scope,
81+
SignInRedirectURI: clientConfig.oauth.redirectSignIn,
82+
SignOutRedirectURI: clientConfig.oauth.redirectSignOut,
83+
AppClientId: clientConfig.oauth.clientId,
84+
};
85+
}
7786
mobileConfig.auth = authConfig;
7887
}
7988

0 commit comments

Comments
 (0)