Skip to content

Commit

Permalink
The new okta library doesn't prepend /api/v1 to our URL paths like th…
Browse files Browse the repository at this point in the history
…e old one does (we still use the old one in the absence of an API token, since the new one doesn't support that.) Make our shim prepend /api/v1 to manual requests for the new library like the old library does, and remove explicit /api/v1 from our request paths. (#8807) (#8825)
  • Loading branch information
ncabatoff authored Apr 24, 2020
1 parent 6ea291b commit cb47167
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/credential/okta/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (b *backend) Login(ctx context.Context, req *logical.Request, username stri
StateToken string `json:"stateToken"`
}

authReq, err := shim.NewRequest("POST", "/api/v1/authn", map[string]interface{}{
authReq, err := shim.NewRequest("POST", "authn", map[string]interface{}{
"username": username,
"password": password,
})
Expand Down
9 changes: 9 additions & 0 deletions builtin/credential/okta/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ import (
"github.com/hashicorp/vault/sdk/logical"
)

// To run this test, set the following env variables:
// VAULT_ACC=1
// OKTA_ORG=dev-219337
// OKTA_API_TOKEN=<find in 1password>
// [email protected]
// OKTA_PASSWORD=<find in 1password>
//
// You will need to install the Okta client app on your mobile device and
// setup MFA.
func TestBackend_Config(t *testing.T) {
defaultLeaseTTLVal := time.Hour * 12
maxLeaseTTLVal := time.Hour * 24
Expand Down
4 changes: 4 additions & 0 deletions builtin/credential/okta/path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/go-cleanhttp"
"net/http"
"net/url"
"strings"
"time"

oktaold "github.com/chrismalek/oktasdk-go/okta"
Expand Down Expand Up @@ -282,6 +283,9 @@ func (new *oktaShimNew) Client() *oktanew.Client {
}

func (new *oktaShimNew) NewRequest(method string, url string, body interface{}) (*http.Request, error) {
if !strings.HasPrefix(url, "/") {
url = "/api/v1/" + url
}
return new.client.GetRequestExecutor().NewRequest(method, url, body)
}

Expand Down

0 comments on commit cb47167

Please sign in to comment.