Table of Contents

Class AuthorizationServiceClient

Namespace
Microsoft.ServiceHub.Framework.Services
Assembly
Microsoft.ServiceHub.Framework.dll

A caching client of the IAuthorizationService.

public class AuthorizationServiceClient : IDisposableObservable, IDisposable
Inheritance
AuthorizationServiceClient
Implements
Inherited Members

Constructors

AuthorizationServiceClient(IAuthorizationService, JoinableTaskFactory?, bool)

Initializes a new instance of the AuthorizationServiceClient class.

[Obsolete("Use the overload that does not accept a JoinableTaskFactory instead. This overload will be removed in a future release.", true)]
public AuthorizationServiceClient(IAuthorizationService authorizationService, JoinableTaskFactory? joinableTaskFactory, bool ownsAuthorizationService = true)

Parameters

authorizationService IAuthorizationService

The client proxy of the authorization service that this instance will wrap. This will be disposed (if it implements IDisposable) when this AuthorizationServiceClient is disposed.

joinableTaskFactory JoinableTaskFactory

A means to avoid deadlocks if the authorization service requires the main thread. May be null.

ownsAuthorizationService bool

true to dispose of authorizationService when this instance is disposed; otherwise false.

AuthorizationServiceClient(IAuthorizationService, bool)

Initializes a new instance of the AuthorizationServiceClient class.

public AuthorizationServiceClient(IAuthorizationService authorizationService, bool ownsAuthorizationService = true)

Parameters

authorizationService IAuthorizationService

The client proxy of the authorization service that this instance will wrap. This will be disposed (if it implements IDisposable) when this AuthorizationServiceClient is disposed.

ownsAuthorizationService bool

true to dispose of authorizationService when this instance is disposed; otherwise false.

Properties

AuthorizationService

Gets the authorization service client proxy.

public IAuthorizationService AuthorizationService { get; }

Property Value

IAuthorizationService

IsDisposed

Gets a value indicating whether this instance has been disposed.

public bool IsDisposed { get; }

Property Value

bool

Methods

AuthorizeOrThrowAsync(ProtectedOperation, CancellationToken)

Verifies that the previously authenticated user is authorized to perform some operation, or throws an exception.

public Task AuthorizeOrThrowAsync(ProtectedOperation operation, CancellationToken cancellationToken = default)

Parameters

operation ProtectedOperation

The operation to check authorization for.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that completes successfully if the operation is authorized, or faults if not.

Exceptions

UnauthorizedAccessException

Thrown if the client is not authorized to perform the operation.

CheckAuthorizationAsync(ProtectedOperation, CancellationToken)

Checks whether a previously authenticated user is authorized to perform some operation.

public Task<bool> CheckAuthorizationAsync(ProtectedOperation operation, CancellationToken cancellationToken = default)

Parameters

operation ProtectedOperation

The operation to be performed.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<bool>

true if the client is authorized to perform the operation; false otherwise.

Dispose()

public void Dispose()

GetCredentialsAsync(CancellationToken)

Gets the data to include in the ClientCredentials property of a service request.

public Task<IReadOnlyDictionary<string, string>> GetCredentialsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IReadOnlyDictionary<string, string>>

A set of credentials.

Remarks

If this service was created with credentials in ClientCredentials, this method will return that same set or perhaps a refreshed set representing the same client. If this service was created without credentials, credentials are obtained from the identity running the process hosting this service.

Exceptions

UnauthorizedAccessException

Thrown when credentials are not available, are expired beyond recovery, or revoked.