@@ -13,7 +13,7 @@ const oidcRequiredAttempts = 3;
1313
1414const commandHandlers = {
1515 password : {
16- login : ( payload , scopeAttrs ) => {
16+ login : ( payload , auth_method_id , account_id , scopeAttrs ) => {
1717 if ( payload . attributes . login_name === 'error' ) {
1818 return new Response ( 400 ) ;
1919 } else {
@@ -25,9 +25,9 @@ const commandHandlers = {
2525 scope : scopeAttrs ,
2626 id : 'token123' ,
2727 token : 'thetokenstring' ,
28- account_id : 'authenticatedaccount' ,
28+ account_id : account_id || 'authenticatedaccount' ,
2929 user_id : 'authenticateduser' ,
30- auth_method_id : 'authmethod123' ,
30+ auth_method_id : auth_method_id || 'authmethod123' ,
3131 created_time : '' ,
3232 updated_time : '' ,
3333 last_used_time : '' ,
@@ -61,7 +61,7 @@ const commandHandlers = {
6161 } ,
6262 } ,
6363 ) ,
64- token : ( _ , scopeAttrs ) => {
64+ token : ( _ , auth_method_id , account_id , scopeAttrs ) => {
6565 oidcAttemptCounter ++ ;
6666 if ( oidcAttemptCounter < oidcRequiredAttempts ) {
6767 return new Response ( 202 ) ;
@@ -74,9 +74,9 @@ const commandHandlers = {
7474 scope : scopeAttrs ,
7575 id : 'token123' ,
7676 token : 'thetokenstring' ,
77- account_id : '1' ,
77+ account_id : account_id || '1' ,
7878 user_id : 'authenticateduser' ,
79- auth_method_id : 'authmethod123' ,
79+ auth_method_id : auth_method_id || 'authmethod123' ,
8080 created_time : '' ,
8181 updated_time : '' ,
8282 last_used_time : '' ,
@@ -90,7 +90,7 @@ const commandHandlers = {
9090} ;
9191
9292// Handles all custom methods on /auth-methods/:id route
93- export function authHandler ( { scopes, authMethods } , request ) {
93+ export function authHandler ( { scopes, authMethods, accounts } , request ) {
9494 const [ , id , method ] = request . params . id_method . match (
9595 / (?< id > .[ ^ : ] * ) : (?< method > ( .* ) ) / ,
9696 ) ;
@@ -100,8 +100,14 @@ export function authHandler({ scopes, authMethods }, request) {
100100 const payload = JSON . parse ( request . requestBody ) ;
101101 const { command } = payload ;
102102 const scope = scopes . find ( authMethod . scopeId ) ;
103+ const account = accounts . where ( { authMethodId : authMethod . id } ) ?. models [ 0 ] ;
103104 const scopeAttrs = this . serialize ( scopes . find ( scope . id ) ) ;
104- return commandHandlers [ authMethod . type ] [ command ] ( payload , scopeAttrs ) ;
105+ return commandHandlers [ authMethod . type ] [ command ] (
106+ payload ,
107+ authMethod . id ,
108+ account ?. id ,
109+ scopeAttrs ,
110+ ) ;
105111 }
106112
107113 // TODO: this handler doesn't really belong here, but we already route
0 commit comments