@@ -153,22 +153,27 @@ headers = *{"Authorization": "Bearer " + access_token, …}*
153
153
The following sample Python code gives the access token, which can be used for subsequent API calls to FarmBeats:
154
154
155
155
```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')
172
177
```
173
178
174
179
** HTTP request headers**
0 commit comments