Skip to content

Commit

Permalink
Add additional query config for authentication request
Browse files Browse the repository at this point in the history
  • Loading branch information
wadahiro committed Oct 15, 2018
1 parent 4f626b7 commit b57e718
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME := aws-cli-oidc
VERSION := v0.1.0
VERSION := v0.2.0
REVISION := $(shell git rev-parse --short HEAD)

SRCS := $(shell find . -type f -name '*.go')
Expand Down
21 changes: 19 additions & 2 deletions cmd/get_cred.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/http"
"strings"
"time"

"github.com/beevik/etree"
Expand Down Expand Up @@ -248,13 +249,29 @@ func doLogin(client *OIDCClient) (*TokenResponse, error) {
challenge := v.CodeChallengeS256()
verifier := v.String()

url := client.Authorization().
authReq := client.Authorization().
QueryParam("response_type", "code").
QueryParam("client_id", clientId).
QueryParam("redirect_uri", redirect).
QueryParam("code_challenge", challenge).
QueryParam("code_challenge_method", "S256").
QueryParam("scope", "openid").Url()
QueryParam("scope", "openid")

additionalQuery := client.config.GetString(OIDC_AUTHENTICATION_REQUEST_ADDITIONAL_QUERY)
if additionalQuery != "" {
queries := strings.Split(additionalQuery, "&")
for _, q := range queries {
kv := strings.Split(q, "=")
if len(kv) == 1 {
authReq = authReq.QueryParam(kv[0], "")
} else if len(kv) == 2 {
authReq = authReq.QueryParam(kv[0], kv[1])
} else {
return nil, errors.Errorf("Invalid additional query: %s", q)
}
}
}
url := authReq.Url()

code := launch(client, url.String(), listener)
if code != "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Execute() {
var configdir string

const OIDC_PROVIDER_METADATA_URL = "oidc_provider_metadata_url"
const OIDC_AUTHENTICATION_REQUEST_ADDITIONAL_QUERY = "oidc_authentication_request_additional_query"
const SUCCESSFUL_REDIRECT_URL = "successful_redirect_url"
const FAILURE_REDIRECT_URL = "failure_redirect_url"
const CLIENT_ID = "client_id"
Expand Down
5 changes: 5 additions & 0 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func runSetup() {
Required: true,
Loop: true,
})
additionalQuery, _ := ui.Ask("Additional query for OIDC authentication request (Default: none):", &input.Options{
Default: "",
Required: false,
})
successfulRedirectURL, _ := ui.Ask("Successful redirect URL (Default: none):", &input.Options{
Default: "",
Required: false,
Expand Down Expand Up @@ -64,6 +68,7 @@ func runSetup() {
config := map[string]string{}

config[OIDC_PROVIDER_METADATA_URL] = server
config[OIDC_AUTHENTICATION_REQUEST_ADDITIONAL_QUERY] = additionalQuery
config[SUCCESSFUL_REDIRECT_URL] = successfulRedirectURL
config[FAILURE_REDIRECT_URL] = failureRedirectURL
config[CLIENT_ID] = clientID
Expand Down

0 comments on commit b57e718

Please sign in to comment.