Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more customisation for callback URL #80

Merged
merged 2 commits into from
Nov 13, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
const defaultMount = "oidc"
const defaultPort = "8250"
const defaultCallbackHost = "localhost"
const defaultCallbackMethod = "http"
const defaultCallbackPort = "8250"

var errorRegex = regexp.MustCompile(`(?s)Errors:.*\* *(.*)`)

Expand Down Expand Up @@ -52,9 +54,19 @@ func (h *CLIHandler) Auth(c *api.Client, m map[string]string) (*api.Secret, erro
callbackHost = defaultCallbackHost
}

callbackMethod, ok := m["callbackmethod"]
if !ok {
callbackMethod = defaultCallbackMethod
}

callbackport, ok := m["callbackport"]
if !ok {
callbackport = defaultCallbackPort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also needs to take into account whether port was set in order to maintain the existing behavior.

For example, this command will fail with the PR as is: vault login -method=oidc role=test port=8400. In the released version the redirect_uri is set to 8400, but with the PR it's now getting the default of 8250.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fix that will set callbackport to the value of port if no explicit callbackport option is passed.

}

role := m["role"]

authURL, err := fetchAuthURL(c, role, mount, port, callbackHost)
authURL, err := fetchAuthURL(c, role, mount, callbackport, callbackMethod, callbackHost)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -112,12 +124,12 @@ func (h *CLIHandler) Auth(c *api.Client, m map[string]string) (*api.Secret, erro
}
}

func fetchAuthURL(c *api.Client, role, mount, port string, callbackHost string) (string, error) {
func fetchAuthURL(c *api.Client, role, mount, callbackport string, callbackMethod string, callbackHost string) (string, error) {
var authURL string

data := map[string]interface{}{
"role": role,
"redirect_uri": fmt.Sprintf("http://%s:%s/oidc/callback", callbackHost, port),
"redirect_uri": fmt.Sprintf("%s://%s:%s/oidc/callback", callbackMethod, callbackHost, callbackport),
}

secret, err := c.Logical().Write(fmt.Sprintf("auth/%s/oidc/auth_url", mount), data)
Expand Down Expand Up @@ -229,7 +241,16 @@ Configuration:
Vault role of type "OIDC" to use for authentication.

port=<string>
Optional localhost port to use for OIDC callback (default: 8250).
Optional localhost port to use for OIDC callback (default: 8250).

callbackmethod=<string>
Optional method to to use in OIDC redirect_uri (default: http).

callbackhost=<string>
Optional callback host adddress to use in OIDC redirect_uri (default: localhost).

callbackport=<string>
Optional port to to use in OIDC redirect_uri (default: 8250).
`

return strings.TrimSpace(help)
Expand Down