Add authentication-method: bearer-token

This commit is contained in:
Rodney Lorrimar
2021-08-03 13:02:38 +08:00
parent a59fdc81fc
commit fedc66614f
3 changed files with 12 additions and 4 deletions
+5 -1
View File
@@ -173,7 +173,11 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
token := globals.GetPass() token := globals.GetPass()
authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", globals.Login.Value, token)))) authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", globals.Login.Value, token))))
req.Header.Add("Authorization", authHeader) req.Header.Add("Authorization", authHeader)
} } else if globals.AuthMethod() == "bearer-token" {
token := globals.GetPass()
authHeader := fmt.Sprintf("Bearer %s", token)
req.Header.Add("Authorization", authHeader)
}
return req, nil return req, nil
}) })
+4
View File
@@ -50,6 +50,10 @@ func CmdLogin(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.Comm
log.Noticef("No need to login when using api-token authentication method") log.Noticef("No need to login when using api-token authentication method")
return nil return nil
} }
if globals.AuthMethod() == "bearer-token" {
log.Noticef("No need to login when using bearer-token authentication method")
return nil
}
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks().WithPostCallback(authCallback) ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks().WithPostCallback(authCallback)
for { for {
+3 -3
View File
@@ -30,13 +30,13 @@ func CmdLogoutRegistry() *jiracli.CommandRegistryEntry {
// CmdLogout will attempt to terminate an active Jira session // CmdLogout will attempt to terminate an active Jira session
func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error { func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
if globals.AuthMethod() == "api-token" { if (globals.AuthMethod() == "api-token" || globals.AuthMethod() == "bearer-token") {
log.Noticef("No need to logout when using api-token authentication method") log.Noticef("No need to logout when using api-token or bearer-token authentication method")
if globals.GetPass() != "" && terminal.IsTerminal(int(os.Stdin.Fd())) && terminal.IsTerminal(int(os.Stdout.Fd())) { if globals.GetPass() != "" && terminal.IsTerminal(int(os.Stdin.Fd())) && terminal.IsTerminal(int(os.Stdout.Fd())) {
delete := false delete := false
err := survey.AskOne( err := survey.AskOne(
&survey.Confirm{ &survey.Confirm{
Message: fmt.Sprintf("Delete api-token from password provider [%s]: ", globals.PasswordSource), Message: fmt.Sprintf("Delete token from password provider [%s]: ", globals.PasswordSource),
Default: false, Default: false,
}, },
&delete, &delete,