12
12
from ._client import TextTranslationClient as ServiceClientGenerated
13
13
14
14
DEFAULT_TOKEN_SCOPE = "https://api.microsofttranslator.com/"
15
- DEFAULT_ENTRA_ID_SCOPE = "https://cognitiveservices.azure.com/.default"
15
+ DEFAULT_ENTRA_ID_SCOPE = "https://cognitiveservices.azure.com"
16
+ DEFAULT_SCOPE = "/.default"
16
17
17
18
18
19
def patch_sdk ():
@@ -47,10 +48,20 @@ class TranslatorEntraIdAuthenticationPolicy(BearerTokenCredentialPolicy):
47
48
48
49
:param credential: Translator Entra Id Credentials used to access Translator Resource for global endpoint.
49
50
:type credential: ~azure.core.credentials.TokenCredential
51
+ :keyword str region: Used for National Clouds.
52
+ :keyword str resource_id: Used with both a TokenCredential combined with a region.
53
+ :keyword str audience: Scopes of the credentials.
50
54
"""
51
55
52
- def __init__ (self , credential : TokenCredential , resource_id : str , region : str , scopes : str , ** kwargs : Any ) -> None :
53
- super (TranslatorEntraIdAuthenticationPolicy , self ).__init__ (credential , scopes , ** kwargs )
56
+ def __init__ (
57
+ self ,
58
+ credential : TokenCredential ,
59
+ resource_id : str ,
60
+ region : str ,
61
+ audience : str ,
62
+ ** kwargs : Any
63
+ ) -> None :
64
+ super (TranslatorEntraIdAuthenticationPolicy , self ).__init__ (credential , audience , ** kwargs )
54
65
self .resource_id = resource_id
55
66
self .region = region
56
67
self .translator_credential = credential
@@ -86,19 +97,21 @@ def set_authentication_policy(credential, kwargs):
86
97
elif hasattr (credential , "get_token" ):
87
98
if not kwargs .get ("authentication_policy" ):
88
99
if kwargs .get ("region" ) and kwargs .get ("resource_id" ):
100
+ scope = kwargs .pop ("audience" , DEFAULT_ENTRA_ID_SCOPE ).rstrip ("/" ) + DEFAULT_SCOPE
89
101
kwargs ["authentication_policy" ] = TranslatorEntraIdAuthenticationPolicy (
90
102
credential ,
91
103
kwargs ["resource_id" ],
92
104
kwargs ["region" ],
93
- kwargs . pop ( "scopes" , DEFAULT_ENTRA_ID_SCOPE ) ,
105
+ scope ,
94
106
)
95
107
else :
96
108
if kwargs .get ("resource_id" ) or kwargs .get ("region" ):
97
109
raise ValueError (
98
- "Both 'resource_id' and 'region' must be provided with a TokenCredential for authentication."
110
+ """Both 'resource_id' and 'region' must be provided with a TokenCredential for
111
+ regional resource authentication."""
99
112
)
100
113
kwargs ["authentication_policy" ] = BearerTokenCredentialPolicy (
101
- credential , * kwargs .pop ("scopes " , [ DEFAULT_TOKEN_SCOPE ]) , kwargs
114
+ credential , * [ kwargs .pop ("audience " , DEFAULT_TOKEN_SCOPE )] , kwargs
102
115
)
103
116
104
117
@@ -134,15 +147,16 @@ class TextTranslationClient(ServiceClientGenerated):
134
147
None + AzureKeyCredential - used for global translator endpoint with global Translator resource
135
148
None + TokenCredential - general translator endpoint with token authentication
136
149
None + TokenCredential + Region - general translator endpoint with regional Translator resource
150
+
137
151
:keyword str endpoint: Supported Text Translation endpoints (protocol and hostname, for example:
138
- https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used.
152
+ https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used.
139
153
:keyword credential: Credential used to authenticate with the Translator service
140
154
:paramtype credential: Union[AzureKeyCredential, TokenCredential]
141
155
:keyword str region: Used for National Clouds.
142
156
:keyword str resource_id: Used with both a TokenCredential combined with a region.
143
- :keyword str scopes : Scopes of the credentials.
157
+ :keyword str audience : Scopes of the credentials.
144
158
:keyword str api_version: Default value is "3.0". Note that overriding this default value may
145
- result in unsupported behavior.
159
+ result in unsupported behavior.
146
160
"""
147
161
148
162
@overload
@@ -153,8 +167,8 @@ def __init__(
153
167
region : Optional [str ] = None ,
154
168
endpoint : Optional [str ] = None ,
155
169
resource_id : Optional [str ] = None ,
156
- scopes : Optional [str ] = None ,
157
- api_version = "3.0" ,
170
+ audience : Optional [str ] = None ,
171
+ api_version : str = "3.0" ,
158
172
** kwargs
159
173
): ...
160
174
@@ -165,7 +179,7 @@ def __init__(
165
179
credential : AzureKeyCredential ,
166
180
region : Optional [str ] = None ,
167
181
endpoint : Optional [str ] = None ,
168
- api_version = "3.0" ,
182
+ api_version : str = "3.0" ,
169
183
** kwargs
170
184
): ...
171
185
@@ -174,7 +188,7 @@ def __init__(
174
188
self ,
175
189
* ,
176
190
endpoint : str ,
177
- api_version = "3.0" ,
191
+ api_version : str = "3.0" ,
178
192
** kwargs
179
193
): ...
180
194
0 commit comments