Skip to content

Commit 5829221

Browse files
committed
Add authn_method config param
1 parent 98a5785 commit 5829221

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ These common options are used in multiple APIs. Instead of repeating the same op
322322
| options.showAuthToggle | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`true` | If you wish to disable the login to sign up form toggle button and vice-versa in the auth screen, set this to `false`. |
323323
| options.showRememberMe | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`true` | If you wish to disable the `Stay logged in for 30 days` checkbox in the login screen, set this to `false`. |
324324
| options.isNewTab | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`false` | Call method and open/render in a new browser tab, by default all views open in the same tab. |
325+
| options.authnMethod | array of string with values `passwordless` or `sso` or string with value `passwordless` or `sso` | `undefined` | Value set during `init`.<p><strong>OR</strong></p>`undefined` | Switch between authentication methods version. |
325326
| options.sdkPlatform (private) | string | false | Generated by the SDK. | <strong>NOTE: this is for Moneytree internal use, please do not use it to avoid unintended behavior!</strong><br /><br />Indicating sdk platform. |
326327
| options.sdkVersion (private) | semver | false | Generated by the SDK. | <strong>NOTE: this is for Moneytree internal use, please do not use it to avoid unintended behavior!</strong><br /><br />Indicating sdk version. |
327328

src/__tests__/helper.test.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { constructScopes, getIsTabValue, mergeConfigs, generateConfigs } from '../helper';
22
import packageJson from '../../package.json';
3+
import { ConfigsOptions } from '../typings';
34

45
describe('helper', () => {
56
test('constuctScopes', () => {
@@ -116,17 +117,32 @@ describe('helper', () => {
116117

117118
describe('generateConfigs', () => {
118119
test('with parameter', () => {
120+
const configPayload: ConfigsOptions = {
121+
email: 'email',
122+
backTo: 'backTo',
123+
authAction: 'signup',
124+
showAuthToggle: true,
125+
showRememberMe: true,
126+
authnMethod: 'sso',
127+
}
128+
119129
expect(
120-
generateConfigs({
121-
email: 'email',
122-
backTo: 'backTo',
123-
authAction: 'signup',
124-
showAuthToggle: true,
125-
showRememberMe: true
126-
})
130+
generateConfigs(configPayload)
127131
).toBe(
128132
`sdk_platform=js&sdk_version=${packageJson.version}&email=email&back_to=backTo&auth_action=signup&show_auth_toggle=true` +
129-
`&show_remember_me=true`
133+
`&show_remember_me=true&authn_method=sso`
134+
);
135+
});
136+
137+
test('with authnMethod parameter as an array', () => {
138+
const configPayload: ConfigsOptions = {
139+
authnMethod: ['sso', 'passwordless'],
140+
}
141+
142+
expect(
143+
generateConfigs(configPayload)
144+
).toBe(
145+
`sdk_platform=js&sdk_version=${packageJson.version}&authn_method[]=sso&authn_method[]=passwordless`
130146
);
131147
});
132148

src/__tests__/index.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ describe('index', () => {
2222
const instance = new MtLinkSdk();
2323

2424
instance.init('clientId', {
25-
redirectUri: 'redirectUri'
25+
redirectUri: 'redirectUri',
26+
authnMethod: 'sso'
2627
});
2728

2829
const options = instance.storedOptions;
2930
const storedOptions = {
3031
clientId: options.clientId,
3132
mode: options.mode,
3233
redirectUri: options.redirectUri,
33-
state: options.state
34+
state: options.state,
35+
authnMethod: options.authnMethod
3436
};
3537

3638
const result1 = instance.authorize({ scopes: 'scopes' });

src/helper.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { encode } from 'url-safe-base64';
77
import { v4 as uuid } from 'uuid';
88
import storage from './storage';
99

10-
import { Scopes, InitOptions, ConfigsOptions, AuthAction } from './typings';
10+
import { Scopes, InitOptions, ConfigsOptions, AuthAction, AuthNMethod } from './typings';
1111

1212
export function constructScopes(scopes: Scopes = ''): string | undefined {
1313
return (Array.isArray(scopes) ? scopes.join(' ') : scopes) || undefined;
@@ -64,7 +64,7 @@ export function mergeConfigs(
6464
}
6565

6666
export function generateConfigs(configs: ConfigsOptions = {}): string {
67-
const snakeCaseConfigs: { [key: string]: string | AuthAction | boolean | undefined } = {};
67+
const snakeCaseConfigs: { [key: string]: string | AuthAction | boolean | AuthNMethod[] | undefined } = {};
6868

6969
const configKeys = [
7070
'email',
@@ -75,20 +75,21 @@ export function generateConfigs(configs: ConfigsOptions = {}): string {
7575
'isNewTab',
7676
'forceLogout',
7777
'sdkPlatform',
78-
'sdkVersion'
78+
'sdkVersion',
79+
'authnMethod',
7980
];
8081

8182
for (const key in configs) {
8283
if (configKeys.indexOf(key) !== -1) {
8384
snakeCaseConfigs[snakeCase(key)] = configs[key as keyof ConfigsOptions];
8485
}
8586
}
86-
87+
8788
return stringify({
8889
sdk_platform: 'js',
8990
sdk_version: __VERSION__,
9091
...snakeCaseConfigs
91-
});
92+
}, { indices: false, arrayFormat: 'brackets', encode: false });
9293
}
9394

9495
export function generateCodeChallenge(): string {

src/typings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface PrivateConfigsOptions {
99
sdkVersion?: string; // semver
1010
}
1111

12+
export type AuthNMethod = 'passwordless' | 'sso' | 'credentials';
1213
export interface ConfigsOptions extends PrivateConfigsOptions {
1314
email?: string;
1415
backTo?: string;
@@ -17,6 +18,7 @@ export interface ConfigsOptions extends PrivateConfigsOptions {
1718
showRememberMe?: boolean;
1819
isNewTab?: boolean;
1920
forceLogout?: boolean;
21+
authnMethod?: AuthNMethod | AuthNMethod[];
2022
}
2123

2224
export type ServicesListType = {

0 commit comments

Comments
 (0)