Skip to content

Commit

Permalink
Save access token to user-specified profile if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
erikostien-pingidentity committed Nov 12, 2024
1 parent 503d8df commit 60c579e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/commands/request/request_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,23 @@ func pingoneAuth() (accessToken string, err error) {
return "", err
}

// Store access token and expiry
profileViper := profiles.GetMainConfig().ActiveProfile().ViperInstance()
profileViper.Set(options.RequestAccessTokenOption.ViperKey, pingoneAuthResponse.AccessToken)

currentTime := time.Now().Unix()
tokenExpiry := currentTime + pingoneAuthResponse.ExpiresIn
profileViper.Set(options.RequestAccessTokenExpiryOption.ViperKey, tokenExpiry)

err = profiles.GetMainConfig().SaveProfile(profiles.GetMainConfig().ActiveProfile().Name(), profileViper)
// Store access token and expiry
pName, err := profiles.GetOptionValue(options.RootProfileOption)
if err != nil {
return "", err
}

if pName == "" {
pName = profiles.GetMainConfig().ActiveProfile().Name()
}

profileViper := profiles.GetMainConfig().ViperInstance().Sub(pName)
profileViper.Set(options.RequestAccessTokenOption.ViperKey, pingoneAuthResponse.AccessToken)
profileViper.Set(options.RequestAccessTokenExpiryOption.ViperKey, tokenExpiry)
err = profiles.GetMainConfig().SaveProfile(pName, profileViper)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 60c579e

Please sign in to comment.