# IdentityToken

## class IdentityToken

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object "(in Python v3.15)")

Credentials used to authenticate one OPC UA session.

Create credentials with `anonymous()`, `user_name()`, or `x509()`.

Examples

```
>>> identity = IdentityToken.user_name("operator", "password")
>>> client = OpcUaClient.connect("opc.tcp://localhost:4840", identity=identity)
```

Methods

| [`anonymous`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.IdentityToken.md#instro.opcua.IdentityToken.anonymous "instro.opcua.IdentityToken.anonymous") | Create an anonymous identity. |
| --- | --- |
| [`user_name`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.IdentityToken.md#instro.opcua.IdentityToken.user_name "instro.opcua.IdentityToken.user_name") | Create an identity from a username and password. |
| [`x509`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.IdentityToken.md#instro.opcua.IdentityToken.x509 "instro.opcua.IdentityToken.x509") | Read a user certificate and private key from filesystem paths. |

### static anonymous()

Create an anonymous identity.

Returns:
:   *IdentityToken* – Anonymous session credentials.

### static user_name(username, password)

Create an identity from a username and password.

Parameters:
:   - **username** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      User name, including an empty name if the server permits it.
    - **password** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      Password, including an empty password if the server permits it.

Returns:
:   *IdentityToken* – Username session credentials.

### static x509(certificate_path, private_key_path)

Read a user certificate and private key from filesystem paths.

These credentials authenticate the user, separately from the application’s
certificate configured on the client.

Parameters:
:   - **certificate_path** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") *|* [*PathLike*](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.15)")*[*[*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")*]*)

      DER or PEM certificate path.
    - **private_key_path** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") *|* [*PathLike*](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.15)")*[*[*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")*]*)

      PEM private key path.

Returns:
:   *IdentityToken* – Certificate session credentials.
