Skip to content

Commit

Permalink
fix: add oauth client config for legacy mobile config (#1578)
Browse files Browse the repository at this point in the history
* fix: add oauth client config for legacy mobile config

* PR feedback updates
  • Loading branch information
Amplifiyer authored May 29, 2024
1 parent 530bf2c commit 1146bbd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 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
4 changes: 2 additions & 2 deletions package-lock.json

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

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
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

0 comments on commit 1146bbd

Please sign in to comment.