You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Key and token-based authentication for online endpoints
@@ -35,15 +35,110 @@ Access to retrieve the key or token for an online endpoint is restricted by Azur
35
35
36
36
For more information on using Azure RBAC with Azure Machine Learning, see [Manage access to Azure Machine Learning](how-to-assign-roles.md).
37
37
38
-
To get the key, use [az ml online-endpoint get-credentials](/cli/azure/ml/online-endpoint#az-ml-online-endpoint-get-credentials). This command returns a JSON document that contains the key or token. __Keys__ will be returned in the `primaryKey` and `secondaryKey` fields. __Tokens__ will be returned in the `accessToken` field. Additionally, the `expiryTimeUtc` and `refreshAfterTimeUtc` fields contain the token expiration and refresh times. The following example shows how to use the `--query` parameter to return only the primary key:
To get the key or token, use [az ml online-endpoint get-credentials](/cli/azure/ml/online-endpoint#az-ml-online-endpoint-get-credentials). This command returns a JSON document that contains the key or token.
41
41
42
-
## Score data using the token
42
+
__Keys__ will be returned in the `primaryKey` and `secondaryKey` fields. The following example shows how to use the `--query` parameter to return only the primary key:
43
43
44
-
When calling the online endpoint for scoring, pass the key or token in the authorization header. The following example shows how to use the curl utility to call the online endpoint using a key (if using a token, replace `$ENDPOINT_KEY` with the token value):
44
+
```azurecli
45
+
ENDPOINT_CRED=$(az ml online-endpoint get-credentials -n $ENDPOINT_NAME -o tsv --query primaryKey)
__Tokens__ will be returned in the `accessToken` field:
49
+
50
+
```azurecli
51
+
ENDPOINT_CRED=$(az ml online-endpoint get-credentials -n $ENDPOINT_NAME -o tsv --query accessToken)
52
+
```
53
+
54
+
Additionally, the `expiryTimeUtc` and `refreshAfterTimeUtc` fields contain the token expiration and refresh times.
55
+
56
+
# [Python](#tab/python)
57
+
58
+
To get the key or token, use the [get_keys](/python/api/azure-ai-ml/azure.ai.ml.operations.onlineendpointoperations#azure-ai-ml-operations-onlineendpointoperations-get-keys) method in the `OnlineEndpointOperations` Class.
59
+
60
+
__Keys__ will be returned in the `primary_key` and `secondary_key` fields:
When calling the online endpoint for scoring, pass the key or token in the authorization header. The following example shows how to use the curl utility to call the online endpoint using a key/token:
86
+
87
+
```azurecli
88
+
SCORING_URI=$(az ml online-endpoint show -n $ENDPOINT_NAME -o tsv --query scoring_uri)
When calling the online endpoint for scoring, pass the key or token in the authorization header. The following example shows how to call the online endpoint using a key/token in Python. In the example, replace the `api_key` variable with your key/token you obtained.
96
+
97
+
```Python
98
+
import urllib.request
99
+
import json
100
+
import os
101
+
import ssl
102
+
103
+
defallowSelfSignedHttps(allowed):
104
+
# bypass the server certificate verification on client side
105
+
if allowed andnot os.environ.get('PYTHONHTTPSVERIFY', '') andgetattr(ssl, '_create_unverified_context', None):
0 commit comments