Authentication Service

The DCS Authentication Service processes all DCS sign ins following OAuth 2.0 resource owner password credentials flow. When you enter your DCS credentials, you get an access token (expiring after 24 hours) and a refresh token for authenticating all services.

The Authentication Python client wraps around the Authentication Service REST API available at https://hostname/dcs/auth/api.

Authentication function

ansys.dcs.client.auth.authenticate(url='https://127.0.0.1/dcs', username=None, password=None, refresh_token=None, timeout=10.0, scope='dps dpdb ansft monitor', client_id='external')

Authenticate user with either password or refresh token against DCS authentication service. If successful, the response includes access and refresh tokens.

Parameters:
  • dcs_url (str) – The base path for the server to call, e.g. “https://127.0.0.1/dcs”.

  • username (str) – Username

  • password (str) – Password

  • refresh_token (str, optional) – Refresh token.

  • timeout (float, optional) – Timeout in seconds. Defaults to 10.

  • scope (str, optional) – String containing one or more requested scopes. Defaults to ‘dps dpdb ansft monitor’.

  • client_id (str, optional) – The client type. Defaults to ‘external’.

Returns:

JSON-encoded content of a requests.Response

Return type:

dict

Client object

class ansys.dcs.client.auth.Client(dcs_url, username, password)

A python interface to the Authorization Service API.

Users with admin rights (such as the default dcadmin user) can create new users as well as modify or delete existing ones. Non-admin users are only allowed to query the list of exisiting users.

Parameters:
  • dcs_url (str) – The base path for the server to call, e.g. “https://127.0.0.1/dcs”.

  • username (str) – Username

  • password (str) – Password

Example

>>> from ansys.dcs.client.auth import Client, User
>>> cl = Client(dcs_url="https://127.0.0.1/dcs/", username="dcadmin", password="dcadmin")
>>> existing_users = cl.get_users()
>>> new_user = User(username='test_user', password='dummy',
>>>                 email='test_user@test.com', fullname='Test User',
>>>                 is_admin=False)
>>> cl.create_user(new_user)
create_user(user, as_objects=True)

Create a new user.

Parameters:
delete_user(user)

Delete an existing user.

Parameters:

user (ansys.dcs.client.auth.User) – A User object. Defaults to None.

get_api_info()

Return info like version, build date etc of the Auth API the client is connected to.

get_users(as_objects=True)

Return a list of users.

update_user(user, as_objects=True)

Modify an existing user.

Parameters:

User

class ansys.dcs.client.auth.User(**kwargs)

User resource

Parameters:

**kwargs – Arbitrary keyword arguments, see the User schema below.

Example

>>> new_user = User(username='test_user', password='dummy',
>>>         email='test_user@test.com', fullname='Test User',
>>>         is_admin=False)

The User schema has the following fields:

Name

Type

Description

Validations

id

integer

Unique user ID, generated internally by the server on creation.

username

string

Username.

password

string

Password.

fullname

string

Full name (optional).

email

string

E-mail address (optional).

is_admin

boolean

Whether the user has admin rights or not.