Vertec Python module “vtcauth”

The Vertec Python module “vtcauth” for easy login via OAuth.

Operating mode

Cloud Suite

|

ON-PREMISES

Modules

Services & CRM

Budget & Phases

Purchases

Resource Planning

Business Intelligence

Created: 16.05.2025
Machine translated
Updated: 07.05.2025 | Outsourced from article Vertec Python functions.

From version 6.8 there is the Python module vtcauth to be able to use OAuth authentication in arbitrary extensions and Python scripts in Vertec.

This contains a decorator authenticate to which a config dictionary is passed as argument. The parameters that can be passed in the config dictionary are the following in vtcauth existing instance variables:

prefix
a prefix can be used to automatically read and save the following values from Vertec Property:
  • AccessToken
  • RefreshToken
  • ApplicationID
  • ApplicationSecret

The properties, including prefix, must be named exactly as follows: {prefix}Name. For the prefix “Outlook” OutlookAccessToken, OutlookRefreshToken etc.

If a prefix is specified in the config, these values are automatically read from or saved in the Vertec properties.

If no prefix is specified, these configurations must be specified individually in the config.

logging

Default value is False, but can be overridden with True in the given config. Returns authentication information as output to the Python console.

client_id

Corresponds to the Application ID. Must be specified only if not covered via prefix.

client_secret

Corresponds to the Application Secret. Only to be specified if not covered via prefix.

individual_login

Default value is True. Can be overridden with False if you want to log in as an application.

scope

Defines the amount of access the application requires to a user’s resources. Standard (MS Graph):

"https://graph.microsoft.com/.default offline_access"

Requires only if OAuth is to be used for another endpoint.

response_mode

Default value is query.

redirect_uri

Corresponds to the Vertec callback address and cannot be overridden with the config.

tenant_id

Required when using MS Graph and must be specified with the config accordingly.

auth_base_url

Authorization endpoint. Standard (MS Graph):

"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize"

Requires only if OAuth is to be used for another endpoint.

token_endpoint

Endpoint for the tokens. Designed for MS Graph by default:

"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"

Requires only if OAuth is to be used for another endpoint.

access_token

AccessToken. Must be specified only if not covered via prefix.

refresh_token

RefreshToken. Only to be specified if not covered via prefix.

The minimum call (for MS Graph) in a script looks like this:

from vtcauth import authenticate
# config example using vertec properties with prefix
config_prefix = {
    "tenant_id":"xxxxxxxxxxxxxxxxxxx.onmicrosoft.com",
    "prefix":"DmsSharePoint",
    "logging":True,}
# using decorator from vtcauth with config_prefix dict
@authenticate(config_prefix)

The entire OAuth authentication takes place via the decorator @authenticate(config_prefix) instead.

If the user is not already logged in to the targeted application, he has one minute to authenticate. If he does not log in to the open login dialog of the targeted product within one minute, there is a timeout.

If the token is expired or invalid, a TokenExpiredException This triggers the OAuth mechanism to fetch new tokens. If a RefreshToken is present and valid, the AccessToken is fetched with the RefreshToken. The exception can be executed a maximum of three times in the same call (by default), after which an error is thrown.

Example

In this example, the first 10 sites of a SharePoint are displayed (MS Graph with OAuth authentication):

import requests
from vtcauth import authenticate, TokenExpiredException

# config example using vertec properties with prefix
config_prefix = {
    "tenant_id":"xxxxxxxxxxxxxxxxxxx.onmicrosoft.com",
    "prefix":"DmsSharePoint",
    "logging":True,}

class SharePointSiteQuery:
    # using decorator from vtcauth with config_prefix dict
    @authenticate(config_prefix)
    def get_sites_with_prefix_config(self):
        return self.get_sites()

    def get_sites(self):
        headers = {
            "Authorization": "Bearer {}".format(self.access_token),
            "Content-Type": "application/json",}
        response = requests.get("https://graph.microsoft.com/v1.0/sites?search=*&$top=10", headers=headers)
        if response.ok:
            content = response.json()
        elif: response.status_code == requests.codes.unauthorized:
            raise TokenExpiredException
        else:
            print(response.json().get("error").get("code") + ' - ' + response.json().get("error").get("message"))

query = SharePointSiteQuery()
query.get_sites_with_prefix_config()

The Vertec SharePoint Extension now also uses the module vtcauth internally. This does not change the operation of the extension.

Stub File

The module vtcauth is also supplied as a Stub File.

Netherlands

United Kingdom