Skip to content

Commit c04570c

Browse files
authored
Merge pull request #112623 from sunasing/patch-31
Updated with MSAL library
2 parents 9a90a4f + 9048056 commit c04570c

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,27 @@ headers = {"Authorization": "Bearer " + access_token, …} 
5656
The following Python code sample retrieves the access token. You can then use the token for subsequent API calls to FarmBeats.
5757

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

7582
## HTTP request headers

0 commit comments

Comments
 (0)