Skip to content

Commit 0f3120d

Browse files
Adds support for private key path in config (#133)
* Adds support for private key path in config
1 parent c0ad1dd commit 0f3120d

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

okta/config.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
package okta
1818

1919
import (
20+
"io/ioutil"
21+
"log"
2022
"net/http"
23+
"os"
2124

2225
"github.com/okta/okta-sdk-golang/v2/okta/cache"
2326
)
@@ -180,8 +183,25 @@ func WithScopes(scopes []string) ConfigSetter {
180183
}
181184
}
182185

186+
// WithPrivateKey sets private key key. Can be either a path to a private key or private key itself.
183187
func WithPrivateKey(privateKey string) ConfigSetter {
184188
return func(c *config) {
185-
c.Okta.Client.PrivateKey = privateKey
189+
if fileExists(privateKey) {
190+
content, err := ioutil.ReadFile(privateKey)
191+
if err != nil {
192+
log.Fatalf("failed to read from provided private key file path: %v", err)
193+
}
194+
c.Okta.Client.PrivateKey = string(content)
195+
} else {
196+
c.Okta.Client.PrivateKey = privateKey
197+
}
186198
}
187199
}
200+
201+
func fileExists(filename string) bool {
202+
info, err := os.Stat(filename)
203+
if os.IsNotExist(err) {
204+
return false
205+
}
206+
return !info.IsDir()
207+
}

0 commit comments

Comments
 (0)