@@ -463,6 +463,42 @@ function executeStepAction ([KeeperSecurity.Authentication.IAuthentication] $aut
463463 }
464464}
465465
466+ function getConfigurationForDevice {
467+ param (
468+ [Parameter (Mandatory = $true )] [string ] $Device ,
469+ [Parameter ()] [string ] $Username ,
470+ [Parameter ()] [string ] $Server
471+ )
472+
473+ $deviceToken = $Device.Trim ()
474+ if (-not $deviceToken ) {
475+ Write-Error " Device parameter requires a device_token value." - ErrorAction Stop
476+ }
477+
478+ $configuration = New-Object KeeperSecurity.Configuration.KeeperConfiguration
479+ $configuration.LastLogin = $Username
480+ $configuration.LastServer = $Server
481+
482+ $deviceConf = New-Object KeeperSecurity.Configuration.DeviceConfiguration $deviceToken
483+ if ($Server ) {
484+ $deviceConf.ServerInfo.Put ((New-Object KeeperSecurity.Configuration.DeviceServerConfiguration $Server ))
485+ }
486+ $configuration.Devices.Put ($deviceConf )
487+
488+ if ($Username ) {
489+ $userConf = New-Object KeeperSecurity.Configuration.UserConfiguration $Username
490+ $userConf.Server = $Server
491+ $userConf.LastDevice = New-Object KeeperSecurity.Configuration.UserDeviceConfiguration $deviceToken
492+ $configuration.Users.Put ($userConf )
493+ }
494+
495+ if ($Server ) {
496+ $configuration.Servers.Put ((New-Object KeeperSecurity.Configuration.ServerConfiguration $Server ))
497+ }
498+
499+ return New-Object KeeperSecurity.Configuration.InMemoryConfigurationStorage $configuration
500+ }
501+
466502function Connect-Keeper {
467503 <#
468504 . Synopsis
@@ -487,6 +523,9 @@ function Connect-Keeper {
487523 . Parameter Server
488524 Change default keeper server
489525
526+ . Parameter Device
527+ Device token. When provided, skips loading configuration from file.
528+
490529 . Parameter Config
491530 Config file name
492531
@@ -507,14 +546,23 @@ function Connect-Keeper {
507546 [Parameter (ParameterSetName = ' sso_password' )][switch ] $SsoPassword ,
508547 [Parameter (ParameterSetName = ' sso_provider' )][switch ] $SsoProvider ,
509548 [Parameter ()][string ] $Server ,
549+ [Parameter ()][string ] $Device ,
510550 [Parameter ()][string ] $Config ,
511551 [Parameter ()][switch ] $UseOfflineStorage ,
512552 [Parameter ()][string ] $VaultDatabasePath ,
513553 [Parameter ()][switch ] $SkipSync
514554 )
515555
516556 Disconnect-Keeper - Resume | Out-Null
517- if ($Config ) {
557+ $deviceTokenOnly = $false
558+ if ($Device ) {
559+ if ($Config ) {
560+ Write-Error " The Device and Config parameters cannot be used together." - ErrorAction Stop
561+ }
562+ $storage = getConfigurationForDevice - Device $Device - Username $Username - Server $Server
563+ $deviceTokenOnly = $true
564+ }
565+ elseif ($Config ) {
518566 $storage = New-Object KeeperSecurity.Configuration.JsonConfigurationStorage $Config
519567 } else {
520568 $storage = New-Object KeeperSecurity.Configuration.JsonConfigurationStorage
@@ -529,6 +577,7 @@ function Connect-Keeper {
529577 $authFlow = New-Object KeeperSecurity.Authentication.Sync.AuthSync($storage , $endpoint )
530578
531579 $authFlow.AlternatePassword = $SsoPassword.IsPresent
580+ $authFlow.NoNewDevice = $deviceTokenOnly
532581
533582 if (-not $NewLogin.IsPresent -and -not $SsoProvider.IsPresent ) {
534583 if (-not $Username ) {
@@ -565,6 +614,9 @@ function Connect-Keeper {
565614 }
566615 }
567616 $authFlow.ResumeSession = $canResume
617+ if ($deviceTokenOnly ) {
618+ $authFlow.ResumeSession = $false
619+ }
568620 Write-Verbose " Resume Session: $ ( $authFlow.ResumeSession ) "
569621
570622 $biometricPresent = $false
0 commit comments