File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -322,8 +322,13 @@ func (cl *client) DashboardDelete(id string) error {
322322}
323323
324324func (cl * client ) setup (client , secret string ) error {
325+ baseURL := "https://api2.arduino.cc"
326+ if url := os .Getenv ("IOT_API_URL" ); url != "" {
327+ baseURL = url
328+ }
329+
325330 // Get the access token in exchange of client_id and client_secret
326- tok , err := token (client , secret )
331+ tok , err := token (client , secret , baseURL )
327332 if err != nil {
328333 err = fmt .Errorf ("cannot retrieve token given client and secret: %w" , err )
329334 return err
@@ -334,7 +339,9 @@ func (cl *client) setup(client, secret string) error {
334339
335340 // Create an instance of the iot-api Go client, we pass an empty config
336341 // because defaults are ok
337- cl .api = iotclient .NewAPIClient (iotclient .NewConfiguration ())
342+ config := iotclient .NewConfiguration ()
343+ config .BasePath = baseURL + "/iot"
344+ cl .api = iotclient .NewAPIClient (config )
338345
339346 return nil
340347}
Original file line number Diff line number Diff line change @@ -25,17 +25,18 @@ import (
2525 cc "golang.org/x/oauth2/clientcredentials"
2626)
2727
28- func token (client , secret string ) (* oauth2.Token , error ) {
28+ func token (client , secret , baseURL string ) (* oauth2.Token , error ) {
2929 // We need to pass the additional "audience" var to request an access token
3030 additionalValues := url.Values {}
3131 additionalValues .Add ("audience" , "https://api2.arduino.cc/iot" )
3232 // Set up OAuth2 configuration
3333 config := cc.Config {
3434 ClientID : client ,
3535 ClientSecret : secret ,
36- TokenURL : "https://api2.arduino.cc /iot/v1/clients/token" ,
36+ TokenURL : baseURL + " /iot/v1/clients/token" ,
3737 EndpointParams : additionalValues ,
3838 }
39+
3940 // Get the access token in exchange of client_id and client_secret
4041 return config .Token (context .Background ())
4142}
You can’t perform that action at this time.
0 commit comments