|
53 |
from univention.lib.i18n import Translation |
53 |
from univention.lib.i18n import Translation |
54 |
from univention.office365.logging2udebug import get_logger |
54 |
from univention.office365.logging2udebug import get_logger |
55 |
from univention.config_registry.frontend import ucr_update |
55 |
from univention.config_registry.frontend import ucr_update |
|
|
56 |
from univention.config_registry import ConfigRegistry |
56 |
|
57 |
|
57 |
|
58 |
|
58 |
_ = Translation('univention-office365').translate |
59 |
_ = Translation('univention-office365').translate |
|
78 |
federation_metadata_url = "https://login.microsoftonline.com/{tenant_id}/federationmetadata/2007-06/federationmetadata.xml" |
79 |
federation_metadata_url = "https://login.microsoftonline.com/{tenant_id}/federationmetadata/2007-06/federationmetadata.xml" |
79 |
resource_url = "https://graph.windows.net" |
80 |
resource_url = "https://graph.windows.net" |
80 |
|
81 |
|
|
|
82 |
ucr = ConfigRegistry() |
83 |
ucr.load() |
81 |
logger = get_logger("office365", "o365") |
84 |
logger = get_logger("office365", "o365") |
82 |
|
85 |
|
83 |
|
86 |
|
|
219 |
json.dump(data, fd) |
222 |
json.dump(data, fd) |
220 |
|
223 |
|
221 |
|
224 |
|
|
|
225 |
def get_http_proxies(): |
226 |
res = dict() |
227 |
if ucr['proxy/http']: |
228 |
res['http'] = ucr['proxy/http'] |
229 |
if ucr['proxy/https']: |
230 |
res['https'] = ucr['proxy/https'] |
231 |
return res |
232 |
|
233 |
|
222 |
class AzureAuth(object): |
234 |
class AzureAuth(object): |
223 |
|
235 |
|
224 |
def __init__(self, name): |
236 |
def __init__(self, name): |
|
368 |
# the certificates with which the tokens were signed can be downloaded from the federation metadata document |
380 |
# the certificates with which the tokens were signed can be downloaded from the federation metadata document |
369 |
# https://msdn.microsoft.com/en-us/library/azure/dn195592.aspx |
381 |
# https://msdn.microsoft.com/en-us/library/azure/dn195592.aspx |
370 |
try: |
382 |
try: |
371 |
fed = requests.get(federation_metadata_url.format(tenant_id=tenant_id)) |
383 |
fed = requests.get(federation_metadata_url.format(tenant_id=tenant_id), proxies=get_http_proxies()) |
372 |
except RequestException as exc: |
384 |
except RequestException as exc: |
373 |
logger.exception("Error downloading federation metadata.") |
385 |
logger.exception("Error downloading federation metadata.") |
374 |
raise TokenValidationError, TokenValidationError(_("Error downloading certificates from Azure. Please run the wizard again."), chained_exc=exc), sys.exc_info()[2] |
386 |
raise TokenValidationError, TokenValidationError(_("Error downloading certificates from Azure. Please run the wizard again."), chained_exc=exc), sys.exc_info()[2] |
|
459 |
url = oauth2_token_url.format(tenant_id=self.tenant_id) |
471 |
url = oauth2_token_url.format(tenant_id=self.tenant_id) |
460 |
|
472 |
|
461 |
logger.debug("POST to URL=%r with data=%r", url, post_form) |
473 |
logger.debug("POST to URL=%r with data=%r", url, post_form) |
462 |
response = requests.post(url, data=post_form, verify=True) |
474 |
response = requests.post(url, data=post_form, verify=True, proxies=get_http_proxies()) |
463 |
if response.status_code != 200: |
475 |
if response.status_code != 200: |
464 |
logger.exception("Error retrieving token (status %r), response: %r", response.status_code, |
476 |
logger.exception("Error retrieving token (status %r), response: %r", response.status_code, |
465 |
response.__dict__) |
477 |
response.__dict__) |