# Class AuthService

Namespace
  adas_core.Application.Services

Assembly
  adas-core.Application.dll

Provides an implementation of the IAuthService interface, offering authentication-related services to consuming components.

    public class AuthService : IAuthService

Inheritance
  object
  AuthService

Implements
  IAuthService

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### AuthService(IOptions<RecordingSettings>, ILogger<AuthService>, IAuthorityRepository)

    public AuthService(IOptions<RecordingSettings> recordingSettings, ILogger<AuthService> logger, IAuthorityRepository authorityRepository)

#### Parameters

`recordingSettings` IOptions<RecordingSettings>
`logger` ILogger<AuthService>
`authorityRepository` IAuthorityRepository

## Methods

### DeleteByDisplayId(ObjectId)

Deletes all authorities associated with the specified display identifier by delegating to the authority repository.

    public Task<bool> DeleteByDisplayId(ObjectId displayId)

#### Parameters

`displayId` ObjectId

  The unique identifier of the display whose related authorities should be removed.

#### Returns

Task<bool>

  A task that resolves to `true` if authorities were successfully deleted; otherwise, `false`.

### DeleteByUnitId(ObjectId)

Deletes all authorities associated with the specified unit identifier by delegating to the authority repository.

    public Task<bool> DeleteByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The identifier of the unit whose authorities are to be removed.

#### Returns

Task<bool>

  A task that represents the asynchronous operation. The task result is `true` if the deletion was successful; otherwise, `false`.

### GetByUnitId(ObjectId)

Retrieves a list of authorizations associated with the specified unit identifier by delegating to the authority repository.

    public Task<List<Authorization>> GetByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The unique identifier of the unit whose authorizations are being retrieved.

#### Returns

Task<List<Authorization>>

  A task that represents the asynchronous operation, containing a list of Authorization objects for the specified unit.

### GetLoginResponse()

Asynchronously obtains a login token from the recording API using the configured client credentials and caches it for reuse via AuthUtils.

    public Task<LoginResponse?> GetLoginResponse()

#### Returns

Task<LoginResponse>

  A LoginResponse containing the authentication token when the request succeeds and the response is valid; otherwise, `null` if the API URL is not configured, the request fails, the returned token is empty, or an exception is caught and logged.

### GetToken()

Retrieves an authentication token, returning the cached token if it is not empty or expired. Otherwise, attempts a fresh login and returns the new token, falling back to an empty string when no token is obtained.

    public Task<string> GetToken()

#### Returns

Task<string>

  A task that resolves to the authentication token, or an empty string if the token could not be obtained.

### GetUserAuthorities(ObjectId)

Retrieves the list of authorizations associated with the specified user identifier.

    public Task<List<Authorization>> GetUserAuthorities(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the user whose authorities are being requested.

#### Returns

Task<List<Authorization>>

  A task that represents the asynchronous operation, containing a list of Authorization entries for the user.