Hi everyone,
I try to create a python script to access my company AD FS server. This ADFS service is crucial to gain a Token to permit script to consume Microsft Dynamics 365 web services ( with authorization bearer token on request header). I find a python package that microsoft created for that kind of purpose: https://pypi.org/project/adal/
I install this package, and all relative dependencies, on Ignition folder:
Inductive Automation\Ignition\user-lib\pylib
Ignition server is 8.0.2 version.
Here my final script code:
import json
import logging
import adal
def turn_on_logging():
logging.basicConfig(level=logging.DEBUG)
#or,
#handler = logging.StreamHandler()
#adal.set_logging_options({
# 'level': 'DEBUG',
# 'handler': handler
#})
#handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
#uncomment for verbose log
print('start logging')
turn_on_logging()
authority_url = "https://myadfsinternalserver/adfs"
activeDirectoryResource = "myResource"
clientId = "myClientID"
clientSecret = "mySecret"
### Main logic begins
auth_context = adal.AuthenticationContext(
authority_url,
validate_authority=False,
api_version=None,
timeout = (1000000, 1000000),
verify_ssl=False
)
print('DONE: create context')
token = auth_context.acquire_token_with_client_credentials(
activeDirectoryResource,
clientId,
clientSecret
)
### Main logic ends
print('DONE: context acquire_token')
print('Here is the token:')
print(json.dumps(token, indent=2))
When I run script I give this error:
Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43)
[OpenJDK 64-Bit Server VM (Azul Systems, Inc.)] on java11.0.3
>>>
start logging
DONE: create context
DEBUG:adal-python:259961c6-e431-4d47-bf0a-7b1d093047ed - Authority:Instance discovery/validation has either already been completed or is turned off: ...
INFO:adal-python:259961c6-e431-4d47-bf0a-7b1d093047ed - TokenRequest:Getting token with client credentials.
DEBUG:adal-python:259961c6-e431-4d47-bf0a-7b1d093047ed - TokenRequest:No user_id passed for cache query
DEBUG:adal-python:259961c6-e431-4d47-bf0a-7b1d093047ed - CacheDriver:finding with query keys: {'_clientId': '...'}
DEBUG:adal-python:259961c6-e431-4d47-bf0a-7b1d093047ed - CacheDriver:Looking for potential cache entries: {'_clientId': '...'}
DEBUG:adal-python:259961c6-e431-4d47-bf0a-7b1d093047ed - CacheDriver:Found 0 potential entries.
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myadfsinternalserver:443
ERROR:adal-python:259961c6-e431-4d47-bf0a-7b1d093047ed - OAuth2Client:Get Token request failed
Traceback (most recent call last):
File "C:\Users\garzon_r\.ignition\cache\gw192.168.200.112_8088\C0\pylib\adal\oauth2_client.py", line 263, in get_token
resp = requests.post(token_url.geturl(),
File "C:\Users\garzon_r\.ignition\cache\gw192.168.200.112_8088\C0\pylib\requests\api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\garzon_r\.ignition\cache\gw192.168.200.112_8088\C0\pylib\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\garzon_r\.ignition\cache\gw192.168.200.112_8088\C0\pylib\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\garzon_r\.ignition\cache\gw192.168.200.112_8088\C0\pylib\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\Users\garzon_r\.ignition\cache\gw192.168.200.112_8088\C0\pylib\requests\adapters.py", line 498, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(10054, 'Socket closed'))
I think there something related with HTTPS and/or Certificate, ecc…
I try this script on a separate python (versione 2.7.x ) stand alone project and everything works fine…
Somebody else have experience with that kind of error or with “adal” package or how to deep trubleshotting ???
Many thanks