Skip to content

Commit b8ea05c

Browse files
adding python sample
1 parent 5ca2be7 commit b8ea05c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

articles/app-service/overview-managed-identity.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.service: app-service
1010
ms.tgt_pltfrm: na
1111
ms.devlang: multiple
1212
ms.topic: article
13-
ms.date: 08/06/2019
13+
ms.date: 08/15/2019
1414
ms.author: mahender
1515
ms.reviewer: yevbronsh
1616

@@ -378,6 +378,25 @@ const getToken = function(resource, apiver, cb) {
378378
}
379379
```
380380

381+
<a name="token-python"></a>In Python:
382+
383+
```python
384+
import os
385+
import requests
386+
387+
msi_endpoint = os.environ["MSI_ENDPOINT"]
388+
msi_secret = os.environ["MSI_SECRET"]
389+
390+
def get_bearer_token(resource_uri, token_api_version):
391+
token_auth_uri = f"{msi_endpoint}?resource={resource_uri}&api-version={token_api_version}"
392+
head_msi = {'Secret':msi_secret}
393+
394+
resp = requests.get(token_auth_uri, headers=head_msi)
395+
access_token = resp.json()['access_token']
396+
397+
return access_token
398+
```
399+
381400
<a name="token-powershell"></a>In PowerShell:
382401

383402
```powershell

0 commit comments

Comments
 (0)