Skip to content

Commit 1170347

Browse files
committed
Pass organization identifier while generating token
1 parent ea7cfdc commit 1170347

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

internal/iot/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,15 @@ func (cl *Client) TemplateApply(ctx context.Context, id, thingId, prefix, device
560560
return dev, nil
561561
}
562562

563-
func (cl *Client) setup(client, secret, organization string) error {
563+
func (cl *Client) setup(client, secret, organizationId string) error {
564564
baseURL := GetArduinoAPIBaseURL()
565565

566566
// Configure a token source given the user's credentials.
567-
cl.token = NewUserTokenSource(client, secret, baseURL)
567+
cl.token = NewUserTokenSource(client, secret, baseURL, organizationId)
568568

569569
config := iotclient.NewConfiguration()
570-
if organization != "" {
571-
config.AddDefaultHeader("X-Organization", organization)
570+
if organizationId != "" {
571+
config.AddDefaultHeader("X-Organization", organizationId)
572572
}
573573
config.Servers = iotclient.ServerConfigurations{
574574
{

internal/iot/token.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ func GetArduinoAPIBaseURL() string {
3939
}
4040

4141
// Build a new token source to forge api JWT tokens based on provided credentials
42-
func NewUserTokenSource(client, secret, baseURL string) oauth2.TokenSource {
42+
func NewUserTokenSource(client, secret, baseURL, organizationId string) oauth2.TokenSource {
4343
// We need to pass the additional "audience" var to request an access token.
4444
additionalValues := url.Values{}
4545
additionalValues.Add("audience", "https://api2.arduino.cc/iot")
46+
if organizationId != "" {
47+
additionalValues.Add("organization_id", organizationId)
48+
}
4649
// Set up OAuth2 configuration.
4750
config := cc.Config{
4851
ClientID: client,

0 commit comments

Comments
 (0)