@@ -56,20 +56,27 @@ headers = {"Authorization": "Bearer " + access_token, …}
56
56
The following Python code sample retrieves the access token. You can then use the token for subsequent API calls to FarmBeats.
57
57
58
58
``` 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' )
73
80
```
74
81
75
82
## HTTP request headers
0 commit comments