@@ -7,7 +7,15 @@ import { encode } from 'url-safe-base64';
77import { v4 as uuid } from 'uuid' ;
88import storage from './storage' ;
99
10- import { Scopes , InitOptions , ConfigsOptions , AuthAction , AuthnMethod } from './typings' ;
10+ import {
11+ Scopes ,
12+ InitOptions ,
13+ ConfigsOptions ,
14+ AuthAction ,
15+ AuthnMethod ,
16+ supportedAuthnMethod ,
17+ supportedAuthAction
18+ } from './typings' ;
1119
1220export function constructScopes ( scopes : Scopes = '' ) : string | undefined {
1321 return ( Array . isArray ( scopes ) ? scopes . join ( ' ' ) : scopes ) || undefined ;
@@ -79,6 +87,14 @@ export function generateConfigs(configs: ConfigsOptions = {}): string {
7987 'authnMethod'
8088 ] ;
8189
90+ if ( configs . authnMethod ) {
91+ configs . authnMethod = parseAuthnMethod ( configs . authnMethod ) ;
92+ }
93+
94+ if ( configs . authAction ) {
95+ configs . authAction = parseAuthAction ( configs . authAction ) ;
96+ }
97+
8298 for ( const key in configs ) {
8399 if ( configKeys . indexOf ( key ) !== - 1 ) {
84100 snakeCaseConfigs [ snakeCase ( key ) ] = configs [ key as keyof ConfigsOptions ] ;
@@ -95,6 +111,37 @@ export function generateConfigs(configs: ConfigsOptions = {}): string {
95111 ) ;
96112}
97113
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+
124+ return supportedAuthnMethod . includes ( x as AuthnMethod ) ;
125+ }
126+
127+ function parseAuthnMethod ( x : unknown ) : AuthnMethod [ ] | AuthnMethod | undefined {
128+ 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 ) ;
132+ }
133+
134+ return isAuthnMethod ( x ) ? x : undefined ;
135+ }
136+
137+ function isAuthAction ( x : unknown ) : x is AuthAction {
138+ return supportedAuthAction . includes ( x as AuthAction ) ;
139+ }
140+
141+ function parseAuthAction ( x : unknown ) : AuthAction | undefined {
142+ return isAuthAction ( x ) ? x : undefined ;
143+ }
144+
98145export function generateCodeChallenge ( ) : string {
99146 const codeVerifier = uuid ( ) ;
100147
0 commit comments