File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717package okta
1818
1919import (
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.
183187func 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+ }
You can’t perform that action at this time.
0 commit comments