Skip to content

Commit 408eca7

Browse files
authored
Merge pull request #115676 from sunasing/patch-34
Updated with MSAL code snippet
2 parents 9df39fe + 3f065fe commit 408eca7

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

articles/industry/agriculture/sensor-partner-integration-in-azure-farmbeats.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,27 @@ headers = {"Authorization": "Bearer " + access_token, …} 
5959
The following sample Python code gives the access token, which can be used for subsequent API calls to FarmBeats.
6060

6161
```python
62-
import azure 
63-
64-
from azure.common.credentials import ServicePrincipalCredentials 
65-
import adal 
66-
#FarmBeats API Endpoint 
67-
ENDPOINT = "https://<yourdatahub>.azurewebsites.net" [Azure website](https://<yourdatahub>.azurewebsites.net)
68-
CLIENT_ID = "<Your Client ID>"   
69-
CLIENT_SECRET = "<Your Client Secret>"   
70-
TENANT_ID = "<Your Tenant ID>"
71-
AUTHORITY_HOST = 'https://login.microsoftonline.com'
72-
AUTHORITY = AUTHORITY_HOST + '/' + TENANT_ID
73-
#Authenticating with the credentials 
74-
context = adal.AuthenticationContext(AUTHORITY) 
75-
token_response = context.acquire_token_with_client_credentials(ENDPOINT, CLIENT_ID, CLIENT_SECRET) 
76-
#Should get an access token here 
77-
access_token = token_response.get('accessToken') 
62+
import requests
63+
import json
64+
import msal
65+
66+
# Your service principal App ID
67+
CLIENT_ID = "<CLIENT_ID>"
68+
# Your service principal password
69+
CLIENT_SECRET = "<CLIENT_SECRET>"
70+
# Tenant ID for your Azure subscription
71+
TENANT_ID = "<TENANT_ID>"
72+
73+
AUTHORITY_HOST = 'https://login.microsoftonline.com'
74+
AUTHORITY = AUTHORITY_HOST + '/' + TENANT_ID
75+
76+
ENDPOINT = "https://<yourfarmbeatswebsitename-api>.azurewebsites.net"
77+
SCOPE = ENDPOINT + "/.default"
78+
79+
context = msal.ConfidentialClientApplication(CLIENT_ID, authority=AUTHORITY, client_credential=CLIENT_SECRET)
80+
token_response = context.acquire_token_for_client(SCOPE)
81+
# We should get an access token here
82+
access_token = token_response.get('access_token')
7883
```
7984

8085

0 commit comments

Comments
 (0)