|
3 | 3 | import requests
|
4 | 4 |
|
5 | 5 | import office365.logger
|
| 6 | +from office365.azure_env import AzureEnvironment |
6 | 7 | from office365.runtime.auth.authentication_provider import AuthenticationProvider
|
7 | 8 | from office365.runtime.auth.token_response import TokenResponse
|
8 | 9 | from office365.runtime.compat import urlparse
|
9 | 10 | from office365.runtime.http.request_options import RequestOptions
|
10 | 11 |
|
11 | 12 |
|
12 | 13 | class ACSTokenProvider(AuthenticationProvider, office365.logger.LoggerContext):
|
13 |
| - def __init__(self, url, client_id, client_secret, environment="commercial"): |
| 14 | + def __init__(self, url, client_id, client_secret, environment=None): |
14 | 15 | """
|
15 | 16 | Provider to acquire the access token from a Microsoft Azure Access Control Service (ACS)
|
16 | 17 |
|
17 | 18 | :param str client_id: The OAuth client id of the calling application.
|
18 | 19 | :param str client_secret: Secret string that the application uses to prove its identity when requesting a token
|
19 | 20 | :param str url: SharePoint web or site url
|
20 | 21 | :param str environment: The Office 365 Cloud Environment endpoint used for authentication
|
21 |
| - defaults to 'commercial'. |
| 22 | + defaults to 'Azure Global'. |
22 | 23 | """
|
23 | 24 | self.url = url
|
24 | 25 | self.redirect_url = None
|
@@ -61,9 +62,7 @@ def _get_app_only_access_token(self, target_host, target_realm):
|
61 | 62 | self.SharePointPrincipal, target_host, target_realm
|
62 | 63 | )
|
63 | 64 | principal_id = self.get_formatted_principal(self._client_id, None, target_realm)
|
64 |
| - sts_url = self.get_security_token_service_url( |
65 |
| - target_realm, environment=self._environment |
66 |
| - ) |
| 65 | + sts_url = self.get_security_token_service_url(target_realm) |
67 | 66 | oauth2_request = {
|
68 | 67 | "grant_type": "client_credentials",
|
69 | 68 | "client_id": principal_id,
|
@@ -96,11 +95,12 @@ def get_formatted_principal(principal_name, host_name, realm):
|
96 | 95 | return "{0}/{1}@{2}".format(principal_name, host_name, realm)
|
97 | 96 | return "{0}@{1}".format(principal_name, realm)
|
98 | 97 |
|
99 |
| - @staticmethod |
100 |
| - def get_security_token_service_url(realm, environment): |
101 |
| - # type: (str, str) -> str |
102 |
| - if environment == "GCCH": |
103 |
| - return "https://login.microsoftonline.us/{0}/tokens/OAuth/2".format(realm) |
| 98 | + def get_security_token_service_url(self, realm): |
| 99 | + # type: (str) -> str |
| 100 | + if self._environment: |
| 101 | + return "{0}/{1}/tokens/OAuth/2".format( |
| 102 | + AzureEnvironment.get_login_authority(self._environment), realm |
| 103 | + ) |
104 | 104 | else:
|
105 | 105 | return (
|
106 | 106 | "https://accounts.accesscontrol.windows.net/{0}/tokens/OAuth/2".format(
|
|
0 commit comments