> For the complete documentation index, see [llms.txt](https://www.notbank.com/learn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.notbank.com/learn/api-reference/websocket-api/authentication.md).

# Authentication

### AuthenticateUser

**Permissions:** Public\
**CallType:** Synchronous

Authenticates a user.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.authenticate({
  ApiPublicKey: 'api_key',
  ApiSecretKey: 'api_secret', // for security reasons, ApiSecret doesn't go through the net
  UserId: '1',
});
```

{% endtab %}

{% tab title="Java" %}

```java
var response = client.authenticate(
    1,
    "api_key",
    "api_secret").get();

```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models.authenticate_request import AuthenticateRequest

response = client.authenticate(AuthenticateRequest(
    "api_key",
    "api_secret",
    1,
)) 
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "AuthenticateUser",
  "o": "{
    \"APIKey\": \"28c68ac3fcfafc3d4e8d653fe57e5baf\",
    \"Signature\": \"29c15c42e4fabcc9e229421e148e647903927c503ab4578ada55bb13a63a9636\",
    \"UserId\": \"96\",
    \"Nonce\": \"2247733562\"
  }"
}
```

{% endtab %}
{% endtabs %}

| Key       | Value                                                                                                                                                                                                                                                                                                                                     |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| APIKey    | **string**. This is an Notbank-generated key used in user-identification.                                                                                                                                                                                                                                                                 |
| Signature | **string**. A long, alphanumeric string generated by Notbank by using the APIKey and Nonce. To generate your own signature with a different nonce, you can use this [HMAC-Sha256](https://codebeautify.org/hmac-generator) page to encode your nonce, user ID, and API key, in the format NonceUserIdAPIKey using the secret as your key. |
| UserId    | **string**. The ID of the user, stated as a string.                                                                                                                                                                                                                                                                                       |
| Nonce     | **string**. Any arbitrary number or random string used with the APIKey to generate a signature.                                                                                                                                                                                                                                           |

#### Response

```json
//Response if API key is used. 2FA is bypassed.
{
  "m": 1,
  "i": 0,
  "n": "AuthenticateUser",
  "o": "{
    \"Authenticated\": true,
    \"SessionToken\": \"02de4e6d-507d-4e89-8a2c-49a9935d5607\",
    \"User\": {
        \"UserId\": 81,
        \"UserName\": \"example1\",
        \"Email\": \"user@example.com\",
        \"EmailVerified\": true,
        \"AccountId\": 90,
        \"OMSId\": 1,
        \"Use2FA\": true
    },
    \"Locked\": false,
    \"Requires2FA\": false,
    \"EnforceEnable2FA\": false,
    \"TwoFAType\": null,
    \"TwoFAToken\": null,
    \"errormsg\": null
  }"
}
```

| Key           | Value                                                                                                                                                                                   |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authenticated | **boolean**. *True* if the user is authenticated; *false* otherwise.                                                                                                                    |
| User          | **object**. JSON user object, described bellow.                                                                                                                                         |
| Locked        | **boolean**. *True* if the user is currently locked; *false* otherwise. A user may be locked by trying to log in too many times in rapid succession. He must be *unlocked* by an admin. |
| Requires2FA   | **boolean**. *True* if the user must use two-factor authentication; *false* otherwise.                                                                                                  |
| TwoFAType     | **string**. The type of 2FA this user requires. For example, **Google**.                                                                                                                |
| TwoFAToken    | **string**. Default is null.                                                                                                                                                            |
| errormsg      | **string**. A successful receipt of the call returns *null*.                                                                                                                            |

**JSON user object**

| Key           | Value                                                                                                         |
| ------------- | ------------------------------------------------------------------------------------------------------------- |
| UserId        | **integer**. The ID of the user being authenticated on the exchange.                                          |
| UserName      | **string**. The name of the user.                                                                             |
| Email         | **string**. The email address of the user.                                                                    |
| EmailVerified | **boolean**. Whether the email address has been verified by the registration process or directly by an Admin. |
| AccountId     | **integer**. The ID of the account with which the user is associated (each user has a default account).       |
| OMSId         | **integer**. The ID of the OMS on which the user and account are associated.                                  |
| Use2FA        | **boolean**. *True* if the user must use 2FA to log in; *false* otherwise.                                    |

### WebAuthenticateUser

**Permissions:** Public\
**Call Type:** Synchronous

Used to Authenticate a user and retrieve a Session Token, or to re-authenticate using an existing session in case of a page refresh or loss of Websocket connection.

Not applicable in HTTP, see **AuthenticateUser** for HTTP.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getAuthService().webAuthenticateUser({
  SessionToken: 'session-token',
});
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.core.WebAuthenticateUserParamBuilder;

var response = client.webAuthenticateUser(new WebAuthenticateUserParamBuilder()
    .sessionToken("session-token")).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import WebAuthenticateUserRequest

response = client.web_authenticate_user(WebAuthenticateUserRequest(
    session_token="session-token",
))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "WebAuthenticateUser",
  "o": "{
    \"SessionToken\": \"session token\",
    \"JWTToken\": \"json webtoken\",
  }"
}
```

{% endtab %}
{% endtabs %}

> WebAutheticate user is not applicable in HTTP, see Authenticate and AuthenticatUser for HTTP.

| Key          | Value                                                                          |
| ------------ | ------------------------------------------------------------------------------ |
| SessionToken | **string**. The user's existing active session token. **optionally required**. |
| JWTToken     | **string**. JSON Web Token. **optionally required**.                           |

#### Response

```json
//Response if user does not have 2FA enabled.
{
  "m": 1,
  "i": 0,
  "n": "WebAuthenticateUser",
  "o": "{
    \"Authenticated\": true,
    \"SessionToken\": \"64186cfe-b183-46cc-bb68-9645fd9d9ff1\",
    \"UserId\": 1,
    \"twoFaToken\": \"\"
  }"
}

//Response if a user has 2FA enabled. In this case Authenticate2FA needs to be called to complete the authentication
{
  "m": 1,
  "i": 0,
  "n": "WebAuthenticateUser",
  "o": "{
    \"Authenticated\": true,
    \"Requires2FA\": true,
    \"AuthType\": \"Google\",
    \"AddtlInfo\": \"\"
  }"
}
```

| Key           | Value                                                                                  |
| ------------- | -------------------------------------------------------------------------------------- |
| Authenticated | **boolean**. *True* if the user is authenticated; *false* otherwise.                   |
| SessionToken  | **string**. The actual session token granted to the user after successful login.       |
| UserId        | **string**. The ID of the user who got authenticated.                                  |
| twoFAToken    | **string**. Default is an empty string.                                                |
| Requires2FA   | **boolean**. *True* if the user must use two-factor authentication; *false* otherwise. |
| AuthType      | **string**. The type of 2FA this user requires. For example, **Google**.               |
| errormsg      | **string**. A successful receipt of the call returns *null*.                           |

> WebAuthenticateUser is not applicable in HTTP, see Authenticate and AuthenticateUser for HTTP.

### LogOut

**Permissions:** Public\
**Call Type:** Synchronous

Logs a user out

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getAuthService().logOut();
```

{% endtab %}

{% tab title="Java" %}

```java
client.logOut().get();
```

{% endtab %}

{% tab title="Python" %}

```python
client.logout()
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "LogOut",
  "o": ""
}
```

{% endtab %}
{% endtabs %}

No request payload is required for websockets.

For HTTP, the existing session token must be included in the request Headers as aptoken.

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "LogOut",
  "o": "{
    \"result\": \"true\",
    \"errormsg\": \"\",
    \"errorcode\": 0,
    \"detail\": \"\"
  }"
}

```

| Key       | Value                                                                                                                                                                                                                                                                                                                                                               |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| result    | **boolean**. A successful logout request returns *true*; and unsuccessful (an error condition) returns *false*.                                                                                                                                                                                                                                                     |
| errormsg  | <p><strong>string</strong>. A successful logout request returns <em>null</em>; the <em>errormsg</em> parameter for an unsuccessful request returns one of the following messages:<br>Not Authorized (errorcode 20)<br>Invalid Request (errorcode 100)<br>Operation Failed (errorcode 101)<br>Server Error (errorcode 102)<br>Resource Not Found (errorcode 104)</p> |
| errorcode | **integer**. A successful request returns 0. An unsuccessful request returns one of the *errorcodes* shown in the *errormsg* list.                                                                                                                                                                                                                                  |
| detail    | **string**. Message text that the system may send. Usually *null*.                                                                                                                                                                                                                                                                                                  |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.notbank.com/learn/api-reference/websocket-api/authentication.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
