Skip to content

Commit c663c5b

Browse files
committed
The new okta library doesn't prepend /api/v1 to our URL paths like the 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)
1 parent 49ad67c commit c663c5b

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

builtin/credential/okta/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (b *backend) Login(ctx context.Context, req *logical.Request, username stri
100100
StateToken string `json:"stateToken"`
101101
}
102102

103-
authReq, err := shim.NewRequest("POST", "/api/v1/authn", map[string]interface{}{
103+
authReq, err := shim.NewRequest("POST", "authn", map[string]interface{}{
104104
"username": username,
105105
"password": password,
106106
})

builtin/credential/okta/backend_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ import (
1515
"github.com/hashicorp/vault/sdk/logical"
1616
)
1717

18+
// To run this test, set the following env variables:
19+
// VAULT_ACC=1
20+
// OKTA_ORG=dev-219337
21+
// OKTA_API_TOKEN=<find in 1password>
22+
// OKTA_USERNAME=test2@example.com
23+
// OKTA_PASSWORD=<find in 1password>
24+
//
25+
// You will need to install the Okta client app on your mobile device and
26+
// setup MFA.
1827
func TestBackend_Config(t *testing.T) {
1928
defaultLeaseTTLVal := time.Hour * 12
2029
maxLeaseTTLVal := time.Hour * 24

builtin/credential/okta/path_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/go-cleanhttp"
77
"net/http"
88
"net/url"
9+
"strings"
910
"time"
1011

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

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

0 commit comments

Comments
 (0)