Skip to content

Commit 23e839f

Browse files
Updating Documentation to use MSAL & v2 endpoint
1 parent 45a770f commit 23e839f

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

articles/hdinsight/kafka/rest-proxy.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,9 @@ For more information on getting OAuth tokens in python, see [Python Authenticati
9090

9191
```python
9292
#Required python packages
93-
#pip3 install adal
94-
#pip install msrestazure
93+
#pip3 install msal
9594

96-
import adal
97-
from msrestazure.azure_active_directory import AdalAuthentication
98-
from msrestazure.azure_cloud import AZURE_PUBLIC_CLOUD
99-
import requests
95+
import msal
10096

10197
#--------------------------Configure these properties-------------------------------#
10298
# Tenant ID for your Azure Subscription
@@ -109,19 +105,24 @@ client_secret = 'password'
109105
kafkarest_endpoint = "https://<clustername>-kafkarest.azurehdinsight.net"
110106
#--------------------------Configure these properties-------------------------------#
111107

112-
#getting token
113-
login_endpoint = AZURE_PUBLIC_CLOUD.endpoints.active_directory
114-
resource = "https://hib.azurehdinsight.net"
115-
context = adal.AuthenticationContext(login_endpoint + '/' + tenant_id)
108+
# Scope
109+
scope = 'https://hib.azurehdinsight.net/.default'
110+
#Authority
111+
authority = 'https://login.microsoftonline.com/' + tenant_id
116112

117-
token = context.acquire_token_with_client_credentials(
118-
resource,
119-
client_id,
120-
client_secret)
113+
# Create a preferably long-lived app instance which maintains a token cache.
114+
app = msal.ConfidentialClientApplication(
115+
client_id , client_secret, authority,
116+
#cache - For details on how look at this example: https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/app.py
117+
)
121118

122-
accessToken = 'Bearer ' + token['accessToken']
119+
# The pattern to acquire a token looks like this.
120+
result = None
123121

124-
print(accessToken)
122+
result = app.acquire_token_for_client(scopes=[scope])
123+
124+
print(result)
125+
accessToken = result['access_token']
125126

126127
# relative url
127128
getstatus = "/v1/metadata/topics"
@@ -132,10 +133,10 @@ response = requests.get(request_url, headers={'Authorization': accessToken})
132133
print(response.content)
133134
```
134135

135-
Find below another sample on how to get a token from Azure for REST proxy using a curl command. Notice that we need the `resource=https://hib.azurehdinsight.net` specified while getting a token.
136+
Find below another sample on how to get a token from Azure for REST proxy using a curl command. **Notice that we need the `scope=https://hib.azurehdinsight.net/.default` specified while getting a token.**
136137

137138
```cmd
138-
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'client_id=<clientid>&client_secret=<clientsecret>&grant_type=client_credentials&resource=https://hib.azurehdinsight.net' 'https://login.microsoftonline.com/<tenantid>/oauth2/token'
139+
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'client_id=<clientid>&client_secret=<clientsecret>&grant_type=client_credentials&scope=https://hib.azurehdinsight.net/.default' 'https://login.microsoftonline.com/<tenantid>/oauth2/v2.0/token'
139140
```
140141

141142
## Next steps

0 commit comments

Comments
 (0)