Skip to content

Commit b588203

Browse files
committed
drop support for array in AuthnMethod config param
1 parent b92acf7 commit b588203

File tree

3 files changed

+15
-48
lines changed

3 files changed

+15
-48
lines changed

src/__tests__/helper.test.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { constructScopes, getIsTabValue, mergeConfigs, generateConfigs } from '../helper';
22
import packageJson from '../../package.json';
33
import { AuthAction, AuthnMethod, ConfigsOptions } from '../typings';
4-
import { stringify } from 'qs';
54

65
describe('helper', () => {
76
test('constuctScopes', () => {
@@ -133,45 +132,27 @@ describe('helper', () => {
133132
);
134133
});
135134

136-
test('with authnMethod parameter as an array', () => {
137-
const configPayload: ConfigsOptions = {
138-
authnMethod: ['sso', 'passwordless']
139-
};
140-
141-
expect(generateConfigs(configPayload)).toBe(
142-
`sdk_platform=js&sdk_version=${packageJson.version}&authn_method%5B%5D=sso&authn_method%5B%5D=passwordless`
143-
);
144-
});
145-
146135
test('query encoding should make sure config params are also encoded', () => {
147136
const configPayload: ConfigsOptions = {
148137
email: 'email&!@#(*)-304should be_encoded',
149138
backTo: 'backTo #!@with []special= chars',
150139
authAction: 'signup',
151140
showAuthToggle: true,
152141
showRememberMe: true,
153-
authnMethod: ['sso', 'passwordless']
142+
authnMethod: 'sso'
154143
};
155144

156145
expect(generateConfigs(configPayload)).toBe(
157-
`sdk_platform=js&sdk_version=${packageJson.version}&email=email%26%21%40%23%28%2A%29-304should%20be_encoded&back_to=backTo%20%23%21%40with%20%5B%5Dspecial%3D%20chars&auth_action=signup&show_auth_toggle=true&show_remember_me=true&authn_method%5B%5D=sso&authn_method%5B%5D=passwordless`
146+
`sdk_platform=js&sdk_version=${packageJson.version}&email=email%26%21%40%23%28%2A%29-304should%20be_encoded&back_to=backTo%20%23%21%40with%20%5B%5Dspecial%3D%20chars&auth_action=signup&show_auth_toggle=true&show_remember_me=true&authn_method=sso`
158147
);
159148
});
160149

161-
test('Should filter out invalid authnMethod from array and authAction values', () => {
150+
test('Should raise an error when passing an array in authnMethod', () => {
162151
const configPayload: ConfigsOptions = {
163-
email: 'email',
164-
backTo: 'backTo',
165-
authAction: 'invalid-value' as AuthAction,
166-
showAuthToggle: true,
167-
showRememberMe: true,
168-
authnMethod: ['oh-not-valid', 'sso'] as AuthnMethod[]
152+
authnMethod: ['oh-not-valid', 'should raise'] as unknown as AuthnMethod
169153
};
170154

171-
expect(generateConfigs(configPayload)).toBe(
172-
`sdk_platform=js&sdk_version=${packageJson.version}&email=email&back_to=backTo&show_auth_toggle=true` +
173-
`&show_remember_me=true&authn_method=sso`
174-
);
155+
expect(() => generateConfigs(configPayload)).toThrow(TypeError);
175156
});
176157

177158
test('Should reject invalid authnMethod from config', () => {

src/helper.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function mergeConfigs(
7272
}
7373

7474
export function generateConfigs(configs: ConfigsOptions = {}): string {
75-
const snakeCaseConfigs: { [key: string]: string | AuthAction | boolean | AuthnMethod[] | undefined } = {};
75+
const snakeCaseConfigs: { [key: string]: string | AuthAction | boolean | undefined } = {};
7676

7777
const configKeys = [
7878
'email',
@@ -101,34 +101,20 @@ export function generateConfigs(configs: ConfigsOptions = {}): string {
101101
}
102102
}
103103

104-
return stringify(
105-
{
106-
sdk_platform: 'js',
107-
sdk_version: __VERSION__,
108-
...snakeCaseConfigs
109-
},
110-
{ indices: false, arrayFormat: 'brackets' }
111-
);
104+
return stringify({
105+
sdk_platform: 'js',
106+
sdk_version: __VERSION__,
107+
...snakeCaseConfigs
108+
});
112109
}
113110

114-
function isAuthnMethod(x: unknown): x is AuthnMethod | AuthnMethod[] {
115-
if (Array.isArray(x)) {
116-
return (
117-
x.length > 0 &&
118-
x.every((el: AuthnMethod) => {
119-
return supportedAuthnMethod.includes(el);
120-
})
121-
);
122-
}
123-
111+
function isAuthnMethod(x: unknown): x is AuthnMethod {
124112
return supportedAuthnMethod.includes(x as AuthnMethod);
125113
}
126114

127-
function parseAuthnMethod(x: unknown): AuthnMethod[] | AuthnMethod | undefined {
115+
function parseAuthnMethod(x: unknown): AuthnMethod | undefined {
128116
if (Array.isArray(x)) {
129-
let filtered_x = x.filter((el: AuthnMethod) => supportedAuthnMethod.includes(el));
130-
131-
filtered_x.length == 1 ? (x = filtered_x.toString()) : (x = filtered_x);
117+
throw new TypeError('Array is not allowed for authnMethod');
132118
}
133119

134120
return isAuthnMethod(x) ? x : undefined;

src/typings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ConfigsOptions extends PrivateConfigsOptions {
2222
showRememberMe?: boolean;
2323
isNewTab?: boolean;
2424
forceLogout?: boolean;
25-
authnMethod?: AuthnMethod | AuthnMethod[];
25+
authnMethod?: AuthnMethod;
2626
}
2727

2828
export type ServicesListType = {

0 commit comments

Comments
 (0)