Skip to content

Commit 9a90a4f

Browse files
authored
Merge pull request #112621 from sunasing/patch-30
Updated with MSAL library
2 parents 2a11e0b + 14b85a5 commit 9a90a4f

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

articles/industry/agriculture/ingest-historical-telemetry-data-in-azure-farmbeats.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,27 @@ headers = *{"Authorization": "Bearer " + access_token, …}*
153153
The following sample Python code gives the access token, which can be used for subsequent API calls to FarmBeats: 
154154
155155
```python
156-
import azure 
157-
158-
from azure.common.credentials import ServicePrincipalCredentials 
159-
import adal 
160-
#FarmBeats API Endpoint 
161-
ENDPOINT = "https://<yourdatahub>.azurewebsites.net" [Azure website](https://<yourdatahub>.azurewebsites.net)
162-
CLIENT_ID = "<Your Client ID>"   
163-
CLIENT_SECRET = "<Your Client Secret>"   
164-
TENANT_ID = "<Your Tenant ID>" 
165-
AUTHORITY_HOST = 'https://login.microsoftonline.com' 
166-
AUTHORITY = AUTHORITY_HOST + '/' + TENANT_ID 
167-
#Authenticating with the credentials 
168-
context = adal.AuthenticationContext(AUTHORITY) 
169-
token_response = context.acquire_token_with_client_credentials(ENDPOINT, CLIENT_ID, CLIENT_SECRET) 
170-
#Should get an access token here 
171-
access_token = token_response.get('accessToken') 
156+
import requests
157+
import json
158+
import msal
159+
160+
# Your service principal App ID
161+
CLIENT_ID = "<CLIENT_ID>"
162+
# Your service principal password
163+
CLIENT_SECRET = "<CLIENT_SECRET>"
164+
# Tenant ID for your Azure subscription
165+
TENANT_ID = "<TENANT_ID>"
166+
167+
AUTHORITY_HOST = 'https://login.microsoftonline.com'
168+
AUTHORITY = AUTHORITY_HOST + '/' + TENANT_ID
169+
170+
ENDPOINT = "https://<yourfarmbeatswebsitename-api>.azurewebsites.net"
171+
SCOPE = ENDPOINT + "/.default"
172+
173+
context = msal.ConfidentialClientApplication(CLIENT_ID, authority=AUTHORITY, client_credential=CLIENT_SECRET)
174+
token_response = context.acquire_token_for_client(SCOPE)
175+
# We should get an access token here
176+
access_token = token_response.get('access_token')
172177
```
173178

174179
**HTTP request headers**

0 commit comments

Comments
 (0)