Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions codegen #13915

Merged
merged 37 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1bdabc7
feat: added functions codegen
bzsurbhi Sep 5, 2024
8d6afa4
feat: added functions codegen
bzsurbhi Sep 5, 2024
acf5249
feat: added functions auth
bzsurbhi Sep 5, 2024
263bc8a
feat: added functions auth
bzsurbhi Sep 5, 2024
46d8524
feat: added functions auth
bzsurbhi Sep 5, 2024
50dc7a2
feat: added functions auth
bzsurbhi Sep 5, 2024
b9080ec
feat: added functions codegen
bzsurbhi Sep 5, 2024
5120ab4
feat: added functions codegen
bzsurbhi Sep 5, 2024
b88f2e2
feat: added functions codegen
bzsurbhi Sep 5, 2024
8b679a6
feat: added functions codegen
bzsurbhi Sep 5, 2024
80580ce
feat: added functions codegen
bzsurbhi Sep 5, 2024
68327d9
feat: added functions codegen
bzsurbhi Sep 5, 2024
3cc4b61
feat: added yarn.lock file
bzsurbhi Sep 6, 2024
4ac9324
feat: updated functions codegen
bzsurbhi Sep 11, 2024
5a8819b
feat: updated functions codegen
bzsurbhi Sep 11, 2024
c2c5969
feat: updated functions codegen
bzsurbhi Sep 11, 2024
bc1acfa
feat: updated functions codegen
bzsurbhi Sep 11, 2024
1e82262
feat: updated functions codegen
bzsurbhi Sep 11, 2024
1ef8938
feat: update functions codegen
bzsurbhi Sep 12, 2024
a2acb75
feat: update functions codegen
bzsurbhi Sep 12, 2024
47358bd
feat: update functions codegen
bzsurbhi Sep 12, 2024
bfd4be7
feat: update functions codegen
bzsurbhi Sep 12, 2024
d4faadd
feat: update functions codegen
bzsurbhi Sep 12, 2024
411511d
feat: update functions codegen
bzsurbhi Sep 12, 2024
dc027e9
feat: update functions codegen
bzsurbhi Sep 12, 2024
ba3babf
feat: functions codegeb
bzsurbhi Sep 17, 2024
abf44df
feat: functions codegen
bzsurbhi Sep 17, 2024
5f61c01
feat: functions codegen
bzsurbhi Sep 17, 2024
50e91e2
feat: functions codegen
bzsurbhi Sep 17, 2024
f54457b
feat: updated secret code
bzsurbhi Sep 18, 2024
61dbbac
feat: fixed failing test
bzsurbhi Sep 18, 2024
1945b71
feat: added an assert statement for meta file
bzsurbhi Sep 18, 2024
86c0e5e
feat: updated API.md for amplify-gen1-codegen-function-adapter
bzsurbhi Sep 18, 2024
b4f256c
feat: fixed lint and ran yarn extract-api
bzsurbhi Sep 18, 2024
0ed8fbe
feat: fixed lint
bzsurbhi Sep 18, 2024
9c2b9a6
fix: fix API.md
bzsurbhi Sep 18, 2024
49ed426
fix: fixed warnings in API.md
bzsurbhi Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/amplify-gen1-codegen-auth-adapter/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { GroupType } from '@aws-sdk/client-cognito-identity-provider';
import { IdentityProviderType } from '@aws-sdk/client-cognito-identity-provider';
import { LambdaConfigType } from '@aws-sdk/client-cognito-identity-provider';
import { ProviderDescription } from '@aws-sdk/client-cognito-identity-provider';
import { SoftwareTokenMfaConfigType } from '@aws-sdk/client-cognito-identity-provider';
import { UserPoolClientType } from '@aws-sdk/client-cognito-identity-provider';
import { UserPoolMfaType } from '@aws-sdk/client-cognito-identity-provider';
import { UserPoolType } from '@aws-sdk/client-cognito-identity-provider';

// @public (undocumented)
Expand All @@ -25,6 +27,10 @@ export interface AuthSynthesizerOptions {
// (undocumented)
identityProvidersDetails?: IdentityProviderType[];
// (undocumented)
mfaConfig?: UserPoolMfaType;
// (undocumented)
totpConfig?: SoftwareTokenMfaConfigType;
// (undocumented)
userPool: UserPoolType;
// (undocumented)
webClient?: UserPoolClientType;
Expand All @@ -42,7 +48,7 @@ export interface AuthTriggerConnection {
export type AuthTriggerConnectionSourceMap = Partial<Record<keyof LambdaConfigType, string>>;

// @public (undocumented)
export const getAuthDefinition: ({ userPool, identityProviders, identityProvidersDetails, identityGroups, webClient, authTriggerConnections, guestLogin, }: AuthSynthesizerOptions) => AuthDefinition;
export const getAuthDefinition: ({ userPool, identityProviders, identityProvidersDetails, identityGroups, webClient, authTriggerConnections, guestLogin, mfaConfig, totpConfig, }: AuthSynthesizerOptions) => AuthDefinition;

// (No @packageDocumentation comment for this package)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,144 @@ void describe('auth codegen', () => {
});
assert(result.loginOptions?.facebookLogin);
});
void it('contains oidc login if OIDC identityProvider type is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{ ProviderType: IdentityProviderTypeType.OIDC, ProviderName: 'OIDC_1', ProviderDetails: { oidc_issuer: 'https://example.com' } },
{ ProviderType: IdentityProviderTypeType.OIDC, ProviderName: 'OIDC_2', ProviderDetails: { oidc_issuer: 'https://example.com' } },
],
});
assert(result.loginOptions?.oidcLogin);
});
void it('contains SAML login if SAML identityProvider type is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.SAML,
ProviderName: 'SAML_1',
ProviderDetails: { metadataContent: 'https://example.com' },
},
],
});
assert(result.loginOptions?.samlLogin);
});
});
void describe('OIDC and SAML providers', () => {
void describe('OIDC', () => {
void it('contains name and issuerUrl if OIDC identityProviderDetails is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.OIDC,
ProviderName: 'OIDC_1',
ProviderDetails: {
oidc_issuer: 'https://example.com',
authorize_url: 'https://example.com',
token_url: 'https://example.com',
attributes_url: 'https://example.com',
jwks_uri: 'https://example.com',
},
},
{
ProviderType: IdentityProviderTypeType.OIDC,
ProviderName: 'OIDC_2',
ProviderDetails: { oidc_issuer: 'https://example.com' },
},
],
});
assert.deepEqual(result.loginOptions?.oidcLogin, [
{
endpoints: {
authorization: 'https://example.com',
token: 'https://example.com',
userInfo: 'https://example.com',
jwksUri: 'https://example.com',
},
issuerUrl: 'https://example.com',
name: 'OIDC_1',
},
{ issuerUrl: 'https://example.com', name: 'OIDC_2' },
]);
});
void it('contains attributeMapping if AttributeMapping is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.OIDC,
ProviderName: 'OIDC_1',
ProviderDetails: { oidc_issuer: 'https://example.com' },
AttributeMapping: { name: 'name', phone_number: 'phone_number' },
},
{
ProviderType: IdentityProviderTypeType.OIDC,
ProviderName: 'OIDC_2',
ProviderDetails: { oidc_issuer: 'https://example.com' },
AttributeMapping: { name: 'name', phone_number: 'phone_number' },
},
],
});
assert.deepEqual(result.loginOptions?.oidcLogin, [
{ issuerUrl: 'https://example.com', name: 'OIDC_1', attributeMapping: { fullname: 'name', phoneNumber: 'phone_number' } },
{ issuerUrl: 'https://example.com', name: 'OIDC_2', attributeMapping: { fullname: 'name', phoneNumber: 'phone_number' } },
]);
});
});
void describe('SAML', () => {
void it('contains metadataType URL if SAML identityProviderDetails and metadataURL is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.SAML,
ProviderName: 'SAML_1',
ProviderDetails: { metadataURL: 'https://example.com' },
},
],
});
assert.deepEqual(result.loginOptions?.samlLogin, {
metadata: { metadataContent: 'https://example.com', metadataType: 'URL' },
name: 'SAML_1',
});
});
void it('contains metadataType FILE if SAML identityProviderDetails and metadataContent is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.SAML,
ProviderName: 'SAML_1',
ProviderDetails: { metadataContent: 'https://example.com' },
},
],
});
assert.deepEqual(result.loginOptions?.samlLogin, {
metadata: { metadataContent: 'https://example.com', metadataType: 'FILE' },
name: 'SAML_1',
});
});
void it('contains attributeMapping if AttributeMapping is passed', () => {
const result = getAuthDefinition({
userPool: {},
identityProvidersDetails: [
{
ProviderType: IdentityProviderTypeType.SAML,
ProviderName: 'SAML_1',
ProviderDetails: { metadataContent: 'https://example.com' },
AttributeMapping: { name: 'name', phone_number: 'phone_number' },
},
],
});
assert.deepEqual(result.loginOptions?.samlLogin, {
attributeMapping: { fullname: 'name', phoneNumber: 'phone_number' },
metadata: { metadataContent: 'https://example.com', metadataType: 'FILE' },
name: 'SAML_1',
});
});
});
});
void describe('callback URLs and logout URLs', () => {
void it('contains callback urls if callbackURLs array is passed', () => {
Expand Down Expand Up @@ -113,16 +251,31 @@ void describe('auth codegen', () => {
});
});
void describe('MFA settings', () => {
const modes: UserPoolMfaType[] = ['ON', 'OFF', 'OPTIONAL'];
for (const mode of modes) {
const modeMap: Record<UserPoolMfaType, string> = {
ON: 'REQUIRED',
OFF: 'OFF',
OPTIONAL: 'OPTIONAL',
};

for (const mode of Object.keys(modeMap)) {
void describe(`when ${mode} is passed to mfa`, () => {
void it(`sets multifactor to ${mode}`, () => {
const result = getAuthDefinition({
userPool: { MfaConfiguration: mode },
});
assert.deepEqual(result.mfa, {
mode,
userPool: {},
mfaConfig: mode as UserPoolMfaType,
totpConfig: { Enabled: true },
});
if (mode === 'OFF') {
assert.deepEqual(result.mfa, {
mode: modeMap[mode as UserPoolMfaType],
});
} else {
assert.deepEqual(result.mfa, {
mode: modeMap[mode as UserPoolMfaType],
sms: true,
totp: true,
});
}
});
});
}
Expand Down Expand Up @@ -272,4 +425,44 @@ void describe('auth codegen', () => {
assert.deepEqual(result.groups, []);
});
});
void describe('Oauth Scopes', () => {
void it('sets the oauth scopes', () => {
const result = getAuthDefinition({
userPool: {},
webClient: { AllowedOAuthScopes: ['email', 'openid', 'aws.cognito.signin.user.admin'] },
});
assert.deepEqual(result.loginOptions?.scopes, ['EMAIL', 'OPENID', 'COGNITO_ADMIN']);
});
void it('Does not render anything if no oauth scopes are passed', () => {
const result = getAuthDefinition({
userPool: {},
webClient: {},
});
assert(result.loginOptions?.scopes === undefined);
});
});
void describe('Unauthenticated Login', () => {
void it('sets the guestLogin to true', () => {
const result = getAuthDefinition({
userPool: {},
guestLogin: true,
});
assert(result.guestLogin);
});
void it('sets the guestLogin to false', () => {
const result = getAuthDefinition({
userPool: {},
guestLogin: false,
});
assert(!result.guestLogin);
});
});
void describe('UserPool Name', () => {
void it('sets the userPool name', () => {
const result = getAuthDefinition({
userPool: { Name: 'test' },
});
assert.deepEqual(result.userPoolOverrides, { UserPoolName: 'test', UsernameAttributes: [] });
});
});
});
Loading
Loading