Skip to content

Commit

Permalink
Merge pull request #792 from skorn95/master
Browse files Browse the repository at this point in the history
Initial support for GCCH environments
  • Loading branch information
vgrem authored Dec 6, 2023
2 parents 4684f08 + ce538be commit 41fb3a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion office365/runtime/auth/authentication_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ def with_credentials(self, credentials, **kwargs):
provider = NtlmProvider(credentials.userName, credentials.password)
else:
browser_mode = kwargs.get("browser_mode", False)
environment = kwargs.get("environment")
provider = SamlTokenProvider(
self.url, credentials.userName, credentials.password, browser_mode
self.url, credentials.userName, credentials.password, browser_mode, environment
)
else:
raise ValueError("Unknown credential type")
Expand Down
7 changes: 5 additions & 2 deletions office365/runtime/auth/providers/saml_token_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@ def is_valid_auth_cookies(values):


class SamlTokenProvider(AuthenticationProvider, office365.logger.LoggerContext):
def __init__(self, url, username, password, browser_mode):
def __init__(self, url, username, password, browser_mode, environment='commercial'):
"""
SAML Security Token Service provider (claims-based authentication)
:param str url: Site or Web absolute url
:param str username: Typically a UPN in the form of an email address
:param str password: The password
:param bool browser_mode:
:param str environment: The Office 365 Cloud Environment endpoint used for authentication.
By default, this will be set to commercial ('commercial', 'GCCH')
"""
# Security Token Service info
self._sts_profile = STSProfile(resolve_base_url(url))
self._sts_profile = STSProfile(resolve_base_url(url), environment)
# Obtain authentication cookies, using the browser mode
self._browser_mode = browser_mode
self._environment = environment
# Last occurred error
self.error = ""
self._username = username
Expand Down
7 changes: 5 additions & 2 deletions office365/runtime/auth/sts_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@


class STSProfile(object):
def __init__(self, authority_url):
def __init__(self, authority_url, environment):
"""
:type authority_url: str
"""
self.authorityUrl = authority_url
self.serviceUrl = "https://login.microsoftonline.com"
if environment == "GCCH":
self.serviceUrl = "https://login.microsoftonline.us"
else:
self.serviceUrl = "https://login.microsoftonline.com"
self.securityTokenServicePath = "extSTS.srf"
self.userRealmServicePath = "GetUserRealm.srf"
self.tokenIssuer = "urn:federation:MicrosoftOnline"
Expand Down
7 changes: 5 additions & 2 deletions office365/sharepoint/client_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,23 @@ def with_access_token(self, token_func):
return self

def with_user_credentials(
self, username, password, allow_ntlm=False, browser_mode=False
self, username, password, allow_ntlm=False, browser_mode=False, environment='commercial'
):
# type: (str, str, bool, bool) -> Self
# type: (str, str, bool, bool, str) -> Self
"""
Initializes a client to acquire a token via user credentials.
:param str username: Typically, a UPN in the form of an email address
:param str password: The password
:param bool allow_ntlm: Flag indicates whether NTLM scheme is enabled. Disabled by default
:param bool browser_mode:
:param str environment: The Office 365 Cloud Environment endpoint used for authentication.
By default, this will be set to commercial ('commercial', 'GCCH')
"""
self.authentication_context.with_credentials(
UserCredential(username, password),
allow_ntlm=allow_ntlm,
browser_mode=browser_mode,
environment=environment
)
return self

Expand Down

0 comments on commit 41fb3a8

Please sign in to comment.