Authentication

There are many ways of how to connect the Python client to system:inmation. See below for all available options with example code.

Basic Access Authentication

Provide the profile name and password when using the username and password authentication strategy. In case you need to create a new profile in DataStudio refer to How to Create a Profile page.

from inmation_api_client import Options

options = Options({
    'auth': {
        'username': '',
        'password': '',
    }
})

Advanced Authentication Options

Authentication (auth) and authorization fields:

from inmation_api_client import Options

options = Options({
    'auth': {
        'username': '',
        'password': '',
        'authority': 'inmation | ad | machine',
        'grant_type': 'password',
        'include_claims': ['email', 'family_name', 'given_name', 'middle_name', 'phone_number']
    },
    'authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...'
})
  • authority can be inmation, ad (Active Directory - domain account) or machine (local account).

  • username can be provided in User Principal Name or Down-Level Logon Name, source.

  • include_claims can only be used in combination with authority set to ad. The token will not be returned to the client but passed via the req argument into ExecFunction implementation.

Check the Web API version which authorization options it supports.

Examples

When connecting to system:inmation you can provide either an inmation_api_client.Options object or a dict in the form described above. The object is passed as options argument to the Client.Connect() method.

Basic authentication

The token below is created by base64-encoding the profile name and password.

from base64 import b64encode
from inmation_api_client import Client, Options

auth_data = 'USERNAME:PASSWORD'  # pay attention to the colon
token = b64encode(auth_data.encode()).decode()
opt = Options()
opt.authorization = "Basic {}".format(token)

# Connecting
Client.Connect('127.0.0.1', 8002, opt)
# OR
Client.Connect(options=opt)

Bearer token authentication

For getting a Bearer token an additional request has to be made, the example below shows one way of how this can be achieved.

import json
from urllib import request, parse
from inmation_api_client import Options

body = {
    'username': '',
    'password': '',
    'grant_type': 'password',
    'authority': 'inmation'
}
body = parse.urlencode(body)

req = request.Request('http://localhost:8002/api/oauth2/token', data=body.encode())
req.add_header('Content-Type', 'application/json')
resp = request.urlopen(req)
resp = json.loads(resp.read().decode())
token = resp['access_token']

options = Options({
    'authorization': 'Bearer {}'.format(token)
})

Active Directory authentication

from inmation_api_client import Options

options = Options({
    'auth': {
        'username': 'user@domain.com',
        'password': 'secret',
        'authority': 'ad',
        'grant_type': 'password'
    }
})