2023-03-15 16:00:52 +00:00
/ * *
* Copyright ( c ) HashiCorp , Inc .
* SPDX - License - Identifier : MPL - 2.0
* /
2021-05-06 18:29:39 +00:00
import Ember from 'ember' ;
2019-02-14 15:39:19 +00:00
import { next } from '@ember/runloop' ;
2018-09-25 16:28:26 +00:00
import { inject as service } from '@ember/service' ;
import { match , alias , or } from '@ember/object/computed' ;
import { dasherize } from '@ember/string' ;
import Component from '@ember/component' ;
2021-04-26 16:23:57 +00:00
import { computed } from '@ember/object' ;
2018-04-03 14:16:57 +00:00
import { supportedAuthBackends } from 'vault/helpers/supported-auth-backends' ;
2021-05-06 18:29:39 +00:00
import { task , timeout } from 'ember-concurrency' ;
2021-12-17 03:44:29 +00:00
import { waitFor } from '@ember/test-waiters' ;
2023-02-28 19:26:10 +00:00
import { v4 as uuidv4 } from 'uuid' ;
2021-12-17 03:44:29 +00:00
2018-04-03 14:16:57 +00:00
const BACKENDS = supportedAuthBackends ( ) ;
2018-04-17 22:04:34 +00:00
2019-04-03 21:06:20 +00:00
/ * *
* @ module AuthForm
* The ` AuthForm ` is used to sign users into Vault .
*
* @ example ` ` ` js
* // All properties are passed in via query params.
2022-08-10 19:46:04 +00:00
* < AuthForm @ wrappedToken = { { wrappedToken } } @ cluster = { { model } } @ namespace = { { namespaceQueryParam } } @ selectedAuth = { { authMethod } } @ onSuccess = { { action this . onSuccess } } / > ` ` `
2019-04-03 21:06:20 +00:00
*
2022-02-17 22:40:25 +00:00
* @ param { string } wrappedToken - The auth method that is currently selected in the dropdown .
* @ param { object } cluster - The auth method that is currently selected in the dropdown . This corresponds to an Ember Model .
* @ param { string } namespace - The currently active namespace .
* @ param { string } selectedAuth - The auth method that is currently selected in the dropdown .
2022-08-10 19:46:04 +00:00
* @ param { function } onSuccess - Fired on auth success .
* @ param { function } [ setOktaNumberChallenge ] - Sets whether we are waiting for okta number challenge to be used to sign in .
* @ param { boolean } [ waitingForOktaNumberChallenge = false ] - Determines if we are waiting for the Okta Number Challenge to sign in .
* @ param { function } [ setCancellingAuth ] - Sets whether we are cancelling or not the login authentication for Okta Number Challenge .
* @ param { boolean } [ cancelAuthForOktaNumberChallenge = false ] - Determines if we are cancelling the login authentication for the Okta Number Challenge .
2019-04-03 21:06:20 +00:00
* /
2018-04-17 22:04:34 +00:00
const DEFAULTS = {
token : null ,
username : null ,
password : null ,
2018-07-20 21:48:25 +00:00
customPath : null ,
2018-04-17 22:04:34 +00:00
} ;
2018-09-25 16:28:26 +00:00
export default Component . extend ( DEFAULTS , {
router : service ( ) ,
auth : service ( ) ,
flashMessages : service ( ) ,
store : service ( ) ,
csp : service ( 'csp-event' ) ,
2018-07-05 18:28:12 +00:00
2019-02-14 15:39:19 +00:00
// passed in via a query param
2018-07-05 18:28:12 +00:00
selectedAuth : null ,
methods : null ,
cluster : null ,
2018-08-16 17:48:24 +00:00
namespace : null ,
2018-09-25 16:28:26 +00:00
wrappedToken : null ,
2018-08-16 17:48:24 +00:00
// internal
oldNamespace : null ,
2022-03-17 22:41:41 +00:00
authMethods : BACKENDS ,
2019-10-01 20:30:56 +00:00
2022-08-10 19:46:04 +00:00
// number answer for okta number challenge if applicable
oktaNumberChallengeAnswer : null ,
2018-08-16 17:48:24 +00:00
didReceiveAttrs ( ) {
this . _super ( ... arguments ) ;
2022-11-09 23:15:31 +00:00
const {
2019-10-01 20:30:56 +00:00
wrappedToken : token ,
oldWrappedToken : oldToken ,
oldNamespace : oldNS ,
namespace : ns ,
selectedAuth : newMethod ,
oldSelectedAuth : oldMethod ,
2022-08-10 19:46:04 +00:00
cancelAuthForOktaNumberChallenge : cancelAuth ,
2019-10-01 20:30:56 +00:00
} = this ;
2022-08-10 19:46:04 +00:00
// if we are cancelling the login then we reset the number challenge answer and cancel the current authenticate and polling tasks
if ( cancelAuth ) {
this . set ( 'oktaNumberChallengeAnswer' , null ) ;
this . authenticate . cancelAll ( ) ;
this . pollForOktaNumberChallenge . cancelAll ( ) ;
}
2019-10-01 20:30:56 +00:00
next ( ( ) => {
if ( ! token && ( oldNS === null || oldNS !== ns ) ) {
this . fetchMethods . perform ( ) ;
}
this . set ( 'oldNamespace' , ns ) ;
// we only want to trigger this once
if ( token && ! oldToken ) {
this . unwrapToken . perform ( token ) ;
this . set ( 'oldWrappedToken' , token ) ;
}
if ( oldMethod && oldMethod !== newMethod ) {
this . resetDefaults ( ) ;
}
this . set ( 'oldSelectedAuth' , newMethod ) ;
} ) ;
2018-08-16 17:48:24 +00:00
} ,
2018-07-05 18:28:12 +00:00
2018-04-03 14:16:57 +00:00
didRender ( ) {
2018-07-05 18:28:12 +00:00
this . _super ( ... arguments ) ;
2018-04-03 14:16:57 +00:00
// on very narrow viewports the active tab may be overflowed, so we scroll it into view here
2022-11-09 23:15:31 +00:00
const activeEle = this . element . querySelector ( 'li.is-active' ) ;
2018-07-05 18:28:12 +00:00
if ( activeEle ) {
activeEle . scrollIntoView ( ) ;
}
2019-10-01 20:30:56 +00:00
next ( ( ) => {
2022-11-09 23:15:31 +00:00
const firstMethod = this . firstMethod ( ) ;
2019-10-01 20:30:56 +00:00
// set `with` to the first method
if (
! this . wrappedToken &&
Ember-cli upgrade from ~3.8 to ~3.20 (#9972)
* Update ember-cli to ~3.20
* Remove bad optional-feature
* Remove ember-fetch dep
* re-install ember-fetch
* update model fragments pr
* update ember model fragments correct package name
* update ember composable helpers to solve array helper error
* update ember-concurrency
* add back engine dependencies, automatically removed during ember-cli-upgrade
* make author-form-options component js file otherwise error
* for now comment out withTestWaiter
* add eslint-node and fix if not with unless in templates
* fix linting for tab index of false is now -1 and add type button to all buttons without types
* fix href errors for linting, likely have to come back and fix
* using eslint fix flag to fix all this.gets
* ember modules codemode removed files that had module twice, will fix in next commit
* finish codemode ember-data-codemod needed to rename const model
* more this.get removal codemode did not work
* cont. removal of this.get
* stop mixin rules until figure out how to reconfig them all
* smaller eslint ignores
* get codemode
* testing app small fixes to bring it back after all the changes
* small changes to eslint
* test removal of getProperties
* fix issue with baseKey because value could be unknown needed to add a question mark in nested get
* smaller linting fixes
* get nested fixes
* small linting error fixes
* small linting changes
* working through more small linting changes
* another round of linting modifications
* liniting fixes
* ember module codemod
* quinit dom codemod
* angle bracket codemod
* discovered that components must have js files
* ran all codemods this is all that's left
* small changes to fix get needs two object, should not have been using get.
* fix issue with one input in form field
* fun times with set and onChange from oninput
* fix issue with model not being passed through on secret-edit-display
* fix issue with yarn run test not working, revert without npm run all
* linting and small fix when loading without a selectAuthBackend
* fix failing test with ui-wizard issue
* fix test failure due to model not being asked for correctly with new changes, probably run into this more.
* fix issue with component helper and at props specific to wizard
* rename log to clilog due to conflict with new eslint rule
* small changes for test failures
* component helper at fixes
* Revert to old component style something with new one broke this and can't figure it out for now
* small fishy smelling test fixes will revisit
* small test changes
* more small test changes, appears upgrade treats spaces differently
* comment out code and test that no longer seems relevant but confirm
* clean run on component test though still some potential timing issues on ui-console test
* fixing one auth test issue and timing issue on enable-test
* small mods
* fix this conditional check from upgrade
* linting fixes after master merge
* package updates using yarn upgrade-interactive
* update libraries that did not effect any of the test failures.
* update ember truth helpers library
* settling tests
* Fix ui-panel control group output
* fix features selection test failures
* Fix auth tests (x-vault-token)
* fix shared test
* fix issue with data null on backend
* Revert "Fix auth tests (x-vault-token)"
This reverts commit 89cb174b2f1998efa56d9604d14131415ae65d6f.
* Fix auth tests (x-vault-token) without updating this.set
* Update redirect-to tests
* fix wrapped token test
* skip some flaky test
* fix issue with href and a tags vs buttons
* fix linting
* updates to get tests running (#10409)
* yarn isntall
* increasing resource_class
* whoops
* trying large
* back to xlarge
* Fix param issue on transform item routes
* test fixes
* settle on policies (old) test
* fix browserstack test warning and skips of test confirmed worked
* Fix redirect-to test
* skips
* fix transformation test and skip some kmip
* Skip tests
* Add meep marker to remaining failing tests
* Skip test with failing component
* rever skip on secret-create test
* Skip piece of test that fails due to navigation-input
* fix settings test where can and skip in others after confirming
* fix circle ci test failures
* ssh role settle
* Fix navigate-input and add settled to test
* Remove extra import
* secret cubbyhole and alicloud
* Add settled to gcpkms test
* settles on redirect to test
* Bump browserstack test resource to large
* Update browserstack resource size to xlarge
* update todos
* add back in withTestWaiter
* try and fix credentials conditional action added comment instead
* Update volatile computed properies to get functions
* this step was never reached and we never defined secretType anywhere so I removed
* add settled to policy old test
* Fix navigate-input on policies and leases
* replace ssh test with no var hoping that helps and add settled to other failing tests, unskip console tests
* kmip, transit, role test remove a skip and add in settled
* fix hover copy button, had to remove some testing functionality
* Remove private router service
* remove skip on control ssh and ui panel, fix search select by restructuring how to read the error
* final bit of working through skipped test
* Replace clearNonGlobalModels by linking directly to namespace with href-to
* Remove unused var
* Fix role-ssh id bug by updating form-field-from-model to form-field-group-loop
* Fix transit create id would not update
* Update option toggle selector for ssh-role
* Fix ssh selector
* cleanup pt1
* small clean up
* cleanup part2
* Fix computed on pricing-metrics-form
* small cleanup based on chelseas comments.
Co-authored-by: Chelsea Shaw <chelshaw.dev@gmail.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
2020-12-03 23:00:22 +00:00
( ( this . fetchMethods . isIdle && firstMethod && ! this . selectedAuth ) ||
( this . selectedAuth && ! this . selectedAuthBackend ) )
2019-10-01 20:30:56 +00:00
) {
this . set ( 'selectedAuth' , firstMethod ) ;
}
} ) ;
2018-07-05 18:28:12 +00:00
} ,
firstMethod ( ) {
2022-11-09 23:15:31 +00:00
const firstMethod = this . methodsToShow . firstObject ;
2018-09-25 16:28:26 +00:00
if ( ! firstMethod ) return ;
2018-07-05 18:28:12 +00:00
// prefer backends with a path over those with a type
2021-04-26 16:23:57 +00:00
return firstMethod . path || firstMethod . type ;
2018-04-03 14:16:57 +00:00
} ,
2018-04-17 22:04:34 +00:00
resetDefaults ( ) {
this . setProperties ( DEFAULTS ) ;
} ,
2022-03-18 15:40:17 +00:00
getAuthBackend ( type ) {
const { wrappedToken , methods , selectedAuth , selectedAuthIsPath : keyIsPath } = this ;
const selected = type || selectedAuth ;
if ( ! methods && ! wrappedToken ) {
return { } ;
}
2022-04-07 14:30:29 +00:00
// if type is provided we can ignore path since we are attempting to lookup a specific backend by type
if ( keyIsPath && ! type ) {
2022-03-18 15:40:17 +00:00
return methods . findBy ( 'path' , selected ) ;
}
return BACKENDS . findBy ( 'type' , selected ) ;
} ,
2018-09-25 16:28:26 +00:00
selectedAuthIsPath : match ( 'selectedAuth' , /\/$/ ) ,
2019-10-01 20:30:56 +00:00
selectedAuthBackend : computed (
'wrappedToken' ,
'methods' ,
'methods.[]' ,
'selectedAuth' ,
'selectedAuthIsPath' ,
2021-12-17 03:44:29 +00:00
function ( ) {
2022-03-18 15:40:17 +00:00
return this . getAuthBackend ( ) ;
2018-09-25 16:28:26 +00:00
}
2019-10-01 20:30:56 +00:00
) ,
2018-04-03 14:16:57 +00:00
2021-12-17 03:44:29 +00:00
providerName : computed ( 'selectedAuthBackend.type' , function ( ) {
Ember-cli upgrade from ~3.8 to ~3.20 (#9972)
* Update ember-cli to ~3.20
* Remove bad optional-feature
* Remove ember-fetch dep
* re-install ember-fetch
* update model fragments pr
* update ember model fragments correct package name
* update ember composable helpers to solve array helper error
* update ember-concurrency
* add back engine dependencies, automatically removed during ember-cli-upgrade
* make author-form-options component js file otherwise error
* for now comment out withTestWaiter
* add eslint-node and fix if not with unless in templates
* fix linting for tab index of false is now -1 and add type button to all buttons without types
* fix href errors for linting, likely have to come back and fix
* using eslint fix flag to fix all this.gets
* ember modules codemode removed files that had module twice, will fix in next commit
* finish codemode ember-data-codemod needed to rename const model
* more this.get removal codemode did not work
* cont. removal of this.get
* stop mixin rules until figure out how to reconfig them all
* smaller eslint ignores
* get codemode
* testing app small fixes to bring it back after all the changes
* small changes to eslint
* test removal of getProperties
* fix issue with baseKey because value could be unknown needed to add a question mark in nested get
* smaller linting fixes
* get nested fixes
* small linting error fixes
* small linting changes
* working through more small linting changes
* another round of linting modifications
* liniting fixes
* ember module codemod
* quinit dom codemod
* angle bracket codemod
* discovered that components must have js files
* ran all codemods this is all that's left
* small changes to fix get needs two object, should not have been using get.
* fix issue with one input in form field
* fun times with set and onChange from oninput
* fix issue with model not being passed through on secret-edit-display
* fix issue with yarn run test not working, revert without npm run all
* linting and small fix when loading without a selectAuthBackend
* fix failing test with ui-wizard issue
* fix test failure due to model not being asked for correctly with new changes, probably run into this more.
* fix issue with component helper and at props specific to wizard
* rename log to clilog due to conflict with new eslint rule
* small changes for test failures
* component helper at fixes
* Revert to old component style something with new one broke this and can't figure it out for now
* small fishy smelling test fixes will revisit
* small test changes
* more small test changes, appears upgrade treats spaces differently
* comment out code and test that no longer seems relevant but confirm
* clean run on component test though still some potential timing issues on ui-console test
* fixing one auth test issue and timing issue on enable-test
* small mods
* fix this conditional check from upgrade
* linting fixes after master merge
* package updates using yarn upgrade-interactive
* update libraries that did not effect any of the test failures.
* update ember truth helpers library
* settling tests
* Fix ui-panel control group output
* fix features selection test failures
* Fix auth tests (x-vault-token)
* fix shared test
* fix issue with data null on backend
* Revert "Fix auth tests (x-vault-token)"
This reverts commit 89cb174b2f1998efa56d9604d14131415ae65d6f.
* Fix auth tests (x-vault-token) without updating this.set
* Update redirect-to tests
* fix wrapped token test
* skip some flaky test
* fix issue with href and a tags vs buttons
* fix linting
* updates to get tests running (#10409)
* yarn isntall
* increasing resource_class
* whoops
* trying large
* back to xlarge
* Fix param issue on transform item routes
* test fixes
* settle on policies (old) test
* fix browserstack test warning and skips of test confirmed worked
* Fix redirect-to test
* skips
* fix transformation test and skip some kmip
* Skip tests
* Add meep marker to remaining failing tests
* Skip test with failing component
* rever skip on secret-create test
* Skip piece of test that fails due to navigation-input
* fix settings test where can and skip in others after confirming
* fix circle ci test failures
* ssh role settle
* Fix navigate-input and add settled to test
* Remove extra import
* secret cubbyhole and alicloud
* Add settled to gcpkms test
* settles on redirect to test
* Bump browserstack test resource to large
* Update browserstack resource size to xlarge
* update todos
* add back in withTestWaiter
* try and fix credentials conditional action added comment instead
* Update volatile computed properies to get functions
* this step was never reached and we never defined secretType anywhere so I removed
* add settled to policy old test
* Fix navigate-input on policies and leases
* replace ssh test with no var hoping that helps and add settled to other failing tests, unskip console tests
* kmip, transit, role test remove a skip and add in settled
* fix hover copy button, had to remove some testing functionality
* Remove private router service
* remove skip on control ssh and ui panel, fix search select by restructuring how to read the error
* final bit of working through skipped test
* Replace clearNonGlobalModels by linking directly to namespace with href-to
* Remove unused var
* Fix role-ssh id bug by updating form-field-from-model to form-field-group-loop
* Fix transit create id would not update
* Update option toggle selector for ssh-role
* Fix ssh selector
* cleanup pt1
* small clean up
* cleanup part2
* Fix computed on pricing-metrics-form
* small cleanup based on chelseas comments.
Co-authored-by: Chelsea Shaw <chelshaw.dev@gmail.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
2020-12-03 23:00:22 +00:00
if ( ! this . selectedAuthBackend ) {
return ;
}
let type = this . selectedAuthBackend . type || 'token' ;
2018-07-05 18:28:12 +00:00
type = type . toLowerCase ( ) ;
2022-11-09 23:15:31 +00:00
const templateName = dasherize ( type ) ;
2021-05-25 17:31:48 +00:00
return templateName ;
2018-04-03 14:16:57 +00:00
} ) ,
2018-09-25 16:28:26 +00:00
hasCSPError : alias ( 'csp.connectionViolations.firstObject' ) ,
2018-04-05 21:36:33 +00:00
cspErrorText : ` This is a standby Vault node but can't communicate with the active node via request forwarding. Sign in at the active node to use the Vault UI. ` ,
2021-12-17 03:44:29 +00:00
allSupportedMethods : computed ( 'methodsToShow' , 'hasMethodsWithPath' , function ( ) {
2022-11-09 23:15:31 +00:00
const hasMethodsWithPath = this . hasMethodsWithPath ;
const methodsToShow = this . methodsToShow ;
2018-07-05 18:28:12 +00:00
return hasMethodsWithPath ? methodsToShow . concat ( BACKENDS ) : methodsToShow ;
} ) ,
2021-12-17 03:44:29 +00:00
hasMethodsWithPath : computed ( 'methodsToShow' , function ( ) {
Ember-cli upgrade from ~3.8 to ~3.20 (#9972)
* Update ember-cli to ~3.20
* Remove bad optional-feature
* Remove ember-fetch dep
* re-install ember-fetch
* update model fragments pr
* update ember model fragments correct package name
* update ember composable helpers to solve array helper error
* update ember-concurrency
* add back engine dependencies, automatically removed during ember-cli-upgrade
* make author-form-options component js file otherwise error
* for now comment out withTestWaiter
* add eslint-node and fix if not with unless in templates
* fix linting for tab index of false is now -1 and add type button to all buttons without types
* fix href errors for linting, likely have to come back and fix
* using eslint fix flag to fix all this.gets
* ember modules codemode removed files that had module twice, will fix in next commit
* finish codemode ember-data-codemod needed to rename const model
* more this.get removal codemode did not work
* cont. removal of this.get
* stop mixin rules until figure out how to reconfig them all
* smaller eslint ignores
* get codemode
* testing app small fixes to bring it back after all the changes
* small changes to eslint
* test removal of getProperties
* fix issue with baseKey because value could be unknown needed to add a question mark in nested get
* smaller linting fixes
* get nested fixes
* small linting error fixes
* small linting changes
* working through more small linting changes
* another round of linting modifications
* liniting fixes
* ember module codemod
* quinit dom codemod
* angle bracket codemod
* discovered that components must have js files
* ran all codemods this is all that's left
* small changes to fix get needs two object, should not have been using get.
* fix issue with one input in form field
* fun times with set and onChange from oninput
* fix issue with model not being passed through on secret-edit-display
* fix issue with yarn run test not working, revert without npm run all
* linting and small fix when loading without a selectAuthBackend
* fix failing test with ui-wizard issue
* fix test failure due to model not being asked for correctly with new changes, probably run into this more.
* fix issue with component helper and at props specific to wizard
* rename log to clilog due to conflict with new eslint rule
* small changes for test failures
* component helper at fixes
* Revert to old component style something with new one broke this and can't figure it out for now
* small fishy smelling test fixes will revisit
* small test changes
* more small test changes, appears upgrade treats spaces differently
* comment out code and test that no longer seems relevant but confirm
* clean run on component test though still some potential timing issues on ui-console test
* fixing one auth test issue and timing issue on enable-test
* small mods
* fix this conditional check from upgrade
* linting fixes after master merge
* package updates using yarn upgrade-interactive
* update libraries that did not effect any of the test failures.
* update ember truth helpers library
* settling tests
* Fix ui-panel control group output
* fix features selection test failures
* Fix auth tests (x-vault-token)
* fix shared test
* fix issue with data null on backend
* Revert "Fix auth tests (x-vault-token)"
This reverts commit 89cb174b2f1998efa56d9604d14131415ae65d6f.
* Fix auth tests (x-vault-token) without updating this.set
* Update redirect-to tests
* fix wrapped token test
* skip some flaky test
* fix issue with href and a tags vs buttons
* fix linting
* updates to get tests running (#10409)
* yarn isntall
* increasing resource_class
* whoops
* trying large
* back to xlarge
* Fix param issue on transform item routes
* test fixes
* settle on policies (old) test
* fix browserstack test warning and skips of test confirmed worked
* Fix redirect-to test
* skips
* fix transformation test and skip some kmip
* Skip tests
* Add meep marker to remaining failing tests
* Skip test with failing component
* rever skip on secret-create test
* Skip piece of test that fails due to navigation-input
* fix settings test where can and skip in others after confirming
* fix circle ci test failures
* ssh role settle
* Fix navigate-input and add settled to test
* Remove extra import
* secret cubbyhole and alicloud
* Add settled to gcpkms test
* settles on redirect to test
* Bump browserstack test resource to large
* Update browserstack resource size to xlarge
* update todos
* add back in withTestWaiter
* try and fix credentials conditional action added comment instead
* Update volatile computed properies to get functions
* this step was never reached and we never defined secretType anywhere so I removed
* add settled to policy old test
* Fix navigate-input on policies and leases
* replace ssh test with no var hoping that helps and add settled to other failing tests, unskip console tests
* kmip, transit, role test remove a skip and add in settled
* fix hover copy button, had to remove some testing functionality
* Remove private router service
* remove skip on control ssh and ui panel, fix search select by restructuring how to read the error
* final bit of working through skipped test
* Replace clearNonGlobalModels by linking directly to namespace with href-to
* Remove unused var
* Fix role-ssh id bug by updating form-field-from-model to form-field-group-loop
* Fix transit create id would not update
* Update option toggle selector for ssh-role
* Fix ssh selector
* cleanup pt1
* small clean up
* cleanup part2
* Fix computed on pricing-metrics-form
* small cleanup based on chelseas comments.
Co-authored-by: Chelsea Shaw <chelshaw.dev@gmail.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
2020-12-03 23:00:22 +00:00
return this . methodsToShow . isAny ( 'path' ) ;
2018-07-05 18:28:12 +00:00
} ) ,
2021-12-17 03:44:29 +00:00
methodsToShow : computed ( 'methods' , function ( ) {
2022-11-09 23:15:31 +00:00
const methods = this . methods || [ ] ;
const shownMethods = methods . filter ( ( m ) =>
2021-12-17 03:44:29 +00:00
BACKENDS . find ( ( b ) => b . type . toLowerCase ( ) === m . type . toLowerCase ( ) )
) ;
2018-07-05 18:28:12 +00:00
return shownMethods . length ? shownMethods : BACKENDS ;
} ) ,
2021-12-17 03:44:29 +00:00
unwrapToken : task (
waitFor ( function * ( token ) {
// will be using the Token Auth Method, so set it here
this . set ( 'selectedAuth' , 'token' ) ;
2022-11-09 23:15:31 +00:00
const adapter = this . store . adapterFor ( 'tools' ) ;
2021-12-17 03:44:29 +00:00
try {
2022-11-09 23:15:31 +00:00
const response = yield adapter . toolAction ( 'unwrap' , null , { clientToken : token } ) ;
2021-12-17 03:44:29 +00:00
this . set ( 'token' , response . auth . client _token ) ;
this . send ( 'doSubmit' ) ;
} catch ( e ) {
this . set ( 'error' , ` Token unwrap failed: ${ e . errors [ 0 ] } ` ) ;
}
} )
) ,
2018-07-05 18:28:12 +00:00
2021-12-17 03:44:29 +00:00
fetchMethods : task (
waitFor ( function * ( ) {
2022-11-09 23:15:31 +00:00
const store = this . store ;
2021-12-17 03:44:29 +00:00
try {
2022-11-09 23:15:31 +00:00
const methods = yield store . findAll ( 'auth-method' , {
2021-12-17 03:44:29 +00:00
adapterOptions : {
unauthenticated : true ,
} ,
} ) ;
this . set (
'methods' ,
methods . map ( ( m ) => {
const method = m . serialize ( { includeId : true } ) ;
return {
... method ,
mountDescription : method . description ,
} ;
} )
) ;
next ( ( ) => {
store . unloadAll ( 'auth-method' ) ;
} ) ;
} catch ( e ) {
this . set ( 'error' , ` There was an error fetching Auth Methods: ${ e . errors [ 0 ] } ` ) ;
}
} )
) ,
2018-08-16 17:48:24 +00:00
2019-02-14 15:39:19 +00:00
showLoading : or ( 'isLoading' , 'authenticate.isRunning' , 'fetchMethods.isRunning' , 'unwrapToken.isRunning' ) ,
2018-08-16 17:48:24 +00:00
2021-12-17 03:44:29 +00:00
authenticate : task (
waitFor ( function * ( backendType , data ) {
2022-03-18 15:40:17 +00:00
const {
selectedAuth ,
cluster : { id : clusterId } ,
} = this ;
2021-12-17 03:44:29 +00:00
try {
2022-08-10 19:46:04 +00:00
if ( backendType === 'okta' ) {
this . pollForOktaNumberChallenge . perform ( data . nonce , data . path ) ;
} else {
this . delayAuthMessageReminder . perform ( ) ;
}
2022-03-18 15:40:17 +00:00
const authResponse = yield this . auth . authenticate ( {
clusterId ,
backend : backendType ,
data ,
selectedAuth ,
} ) ;
2022-02-17 22:40:25 +00:00
this . onSuccess ( authResponse , backendType , data ) ;
2022-02-17 20:17:59 +00:00
} catch ( e ) {
2022-04-07 14:30:29 +00:00
this . set ( 'isLoading' , false ) ;
2022-02-17 22:40:25 +00:00
if ( ! this . auth . mfaError ) {
this . set ( 'error' , ` Authentication failed: ${ this . auth . handleError ( e ) } ` ) ;
}
2021-12-17 03:44:29 +00:00
}
} )
) ,
2018-10-02 13:53:39 +00:00
2022-08-10 19:46:04 +00:00
pollForOktaNumberChallenge : task ( function * ( nonce , mount ) {
// yield for 1s to wait to see if there is a login error before polling
yield timeout ( 1000 ) ;
if ( this . error ) {
return ;
}
let response = null ;
this . setOktaNumberChallenge ( true ) ;
this . setCancellingAuth ( false ) ;
// keep polling /auth/okta/verify/:nonce API every 1s until a response is given with the correct number for the Okta Number Challenge
while ( response === null ) {
// when testing, the polling loop causes promises to be rejected making acceptance tests fail
// so disable the poll in tests
if ( Ember . testing ) {
return ;
}
yield timeout ( 1000 ) ;
response = yield this . auth . getOktaNumberChallengeAnswer ( nonce , mount ) ;
}
this . set ( 'oktaNumberChallengeAnswer' , response ) ;
} ) ,
2021-12-17 03:44:29 +00:00
delayAuthMessageReminder : task ( function * ( ) {
2021-05-06 18:29:39 +00:00
if ( Ember . testing ) {
yield timeout ( 0 ) ;
2022-02-17 22:40:25 +00:00
} else {
yield timeout ( 5000 ) ;
2021-05-06 18:29:39 +00:00
}
} ) ,
2018-04-03 14:16:57 +00:00
actions : {
2022-10-26 21:34:43 +00:00
doSubmit ( passedData , event , token ) {
2022-10-18 15:46:02 +00:00
if ( event ) {
event . preventDefault ( ) ;
2019-02-14 15:39:19 +00:00
}
2022-10-26 21:34:43 +00:00
if ( token ) {
this . set ( 'token' , token ) ;
}
this . set ( 'error' , null ) ;
// if callback from oidc or jwt we have a token at this point
const backend = token ? this . getAuthBackend ( 'token' ) : this . selectedAuthBackend || { } ;
const backendMeta = BACKENDS . find (
2021-12-17 03:44:29 +00:00
( b ) => ( b . type || '' ) . toLowerCase ( ) === ( backend . type || '' ) . toLowerCase ( )
2018-07-05 18:28:12 +00:00
) ;
2022-10-26 21:34:43 +00:00
const attributes = ( backendMeta || { } ) . formAttributes || [ ] ;
const data = this . getProperties ( ... attributes ) ;
2018-04-17 22:04:34 +00:00
2019-02-14 15:39:19 +00:00
if ( passedData ) {
2022-10-26 21:34:43 +00:00
Object . assign ( data , passedData ) ;
2019-02-14 15:39:19 +00:00
}
2021-04-26 16:23:57 +00:00
if ( this . customPath || backend . id ) {
data . path = this . customPath || backend . id ;
2018-04-03 14:16:57 +00:00
}
2022-08-10 19:46:04 +00:00
// add nonce field for okta backend
if ( backend . type === 'okta' ) {
2023-02-28 19:26:10 +00:00
data . nonce = uuidv4 ( ) ;
2022-08-10 19:46:04 +00:00
// add a default path of okta if it doesn't exist to be used for Okta Number Challenge
if ( ! data . path ) {
data . path = 'okta' ;
}
}
2019-02-14 15:39:19 +00:00
return this . authenticate . unlinked ( ) . perform ( backend . type , data ) ;
2018-04-03 14:16:57 +00:00
} ,
2019-04-09 17:42:51 +00:00
handleError ( e ) {
2022-02-17 22:40:25 +00:00
this . setProperties ( {
2022-04-07 14:30:29 +00:00
isLoading : false ,
2022-02-17 22:40:25 +00:00
error : e ? this . auth . handleError ( e ) : null ,
} ) ;
2019-04-09 17:42:51 +00:00
} ,
2022-08-10 19:46:04 +00:00
returnToLoginFromOktaNumberChallenge ( ) {
this . setOktaNumberChallenge ( false ) ;
this . set ( 'oktaNumberChallengeAnswer' , null ) ;
} ,
2018-04-03 14:16:57 +00:00
} ,
} ) ;