@@ -59,22 +59,27 @@ headers = {"Authorization": "Bearer " + access_token, …}
59
59
The following sample Python code gives the access token, which can be used for subsequent API calls to FarmBeats.
60
60
61
61
``` 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' )
78
83
```
79
84
80
85
0 commit comments