Skip to content

AuthenticationClient

Namespace: IntegrationTests.ApiClient

public class AuthenticationClient

Inheritance ObjectAuthenticationClient

Properties

BaseUrl

public string BaseUrl { get; set; }

Property Value

String

ReadResponseAsString

public bool ReadResponseAsString { get; set; }

Property Value

Boolean

Constructors

AuthenticationClient(String, HttpClient)

public AuthenticationClient(string baseUrl, HttpClient httpClient)

Parameters

baseUrl String

httpClient HttpClient

Methods

LoginAsync(Login)

Authenticates a user and returns a JWT token for API access.

public Task<FileResponse> LoginAsync(Login input)

Parameters

input Login

The login credentials containing username and password.

Returns

Authentication successful. Returns JWT access token and refresh token.

Exceptions

ApiException

A server side error occurred.

Remarks:

This endpoint validates user credentials and returns a JWT access token and refresh token.

The returned tokens should be used for authenticating subsequent API requests.

Example request:

json <br>{ <br>"userName": "admin", <br>"password": "your-password" <br>} <br>

Example response:

json <br>{ <br>"accessToken": "CakeIsNotALie.", <br>"refreshToken": "refresh-token-here", <br>"expiresIn": 3600 <br>} <br>

LoginAsync(Login, CancellationToken)

Authenticates a user and returns a JWT token for API access.

public Task<FileResponse> LoginAsync(Login input, CancellationToken cancellationToken)

Parameters

input Login

The login credentials containing username and password.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Authentication successful. Returns JWT access token and refresh token.

Exceptions

ApiException

A server side error occurred.

Remarks:

This endpoint validates user credentials and returns a JWT access token and refresh token.

The returned tokens should be used for authenticating subsequent API requests.

Example request:

json <br>{ <br>"userName": "admin", <br>"password": "your-password" <br>} <br>

Example response:

json <br>{ <br>"accessToken": "CakeIsNotALie.", <br>"refreshToken": "refresh-token-here", <br>"expiresIn": 3600 <br>} <br>

ReadObjectResponseAsync<T>(HttpResponseMessage, IReadOnlyDictionary<String, IEnumerable<String>>, CancellationToken)

protected Task<ObjectResponseResult<T>> ReadObjectResponseAsync<T>(HttpResponseMessage response, IReadOnlyDictionary<String, IEnumerable<String>> headers, CancellationToken cancellationToken)

Type Parameters

T

Parameters

response HttpResponseMessage

headers IReadOnlyDictionary<String, IEnumerable<String>>

cancellationToken CancellationToken

Returns

Task<ObjectResponseResult<T>>

RefreshAsync(JwtToken)

Refreshes an expired JWT access token using a valid refresh token.

public Task RefreshAsync(JwtToken token)

Parameters

token JwtToken

The JWT token object containing both the expired access token and valid refresh token.

Returns

Token refresh successful. Returns new access and refresh tokens.

Exceptions

ApiException

A server side error occurred.

Remarks:

This endpoint allows clients to obtain a new access token without requiring

the user to log in again. The refresh token must be valid and not expired.

Use this endpoint when your access token expires to maintain continuous

authentication without user intervention.

Example request:

json <br>{ <br>"accessToken": "expired-access-token", <br>"refreshToken": "valid-refresh-token" <br>} <br>

Example response:

json <br>{ <br>"accessToken": "new-jwt-access-token", <br>"refreshToken": "new-refresh-token", <br>"expiresIn": 3600 <br>} <br>

RefreshAsync(JwtToken, CancellationToken)

Refreshes an expired JWT access token using a valid refresh token.

public Task RefreshAsync(JwtToken token, CancellationToken cancellationToken)

Parameters

token JwtToken

The JWT token object containing both the expired access token and valid refresh token.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Token refresh successful. Returns new access and refresh tokens.

Exceptions

ApiException

A server side error occurred.

Remarks:

This endpoint allows clients to obtain a new access token without requiring

the user to log in again. The refresh token must be valid and not expired.

Use this endpoint when your access token expires to maintain continuous

authentication without user intervention.

Example request:

json <br>{ <br>"accessToken": "expired-access-token", <br>"refreshToken": "valid-refresh-token" <br>} <br>

Example response:

json <br>{ <br>"accessToken": "new-jwt-access-token", <br>"refreshToken": "new-refresh-token", <br>"expiresIn": 3600 <br>} <br>

RegisterAsync(Register)

Registers a new user in the system. Admin access required.

public Task RegisterAsync(Register input)

Parameters

input Register

The registration data containing username and password for the new user.

Returns

User registered successfully.

Exceptions

ApiException

A server side error occurred.

Remarks:

Only users with the "Admin" role can access this endpoint.

Authorization Required: Bearer token with Admin role

Example request:

json <br>{ <br>"userName": "newuser", <br>"password": "secure-password" <br>} <br>

The new user will be created with the "User" role by default and can access

temperature data endpoints but cannot perform administrative functions.

RegisterAsync(Register, CancellationToken)

Registers a new user in the system. Admin access required.

public Task RegisterAsync(Register input, CancellationToken cancellationToken)

Parameters

input Register

The registration data containing username and password for the new user.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

User registered successfully.

Exceptions

ApiException

A server side error occurred.

Remarks:

Only users with the "Admin" role can access this endpoint.

Authorization Required: Bearer token with Admin role

Example request:

json <br>{ <br>"userName": "newuser", <br>"password": "secure-password" <br>} <br>

The new user will be created with the "User" role by default and can access

temperature data endpoints but cannot perform administrative functions.