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
authorizationServiceIAuthorizationServiceThe client proxy of the authorization service that this instance will wrap. This will be disposed (if it implements IDisposable) when this AuthorizationServiceClient is disposed.
joinableTaskFactoryJoinableTaskFactoryA means to avoid deadlocks if the authorization service requires the main thread. May be null.
ownsAuthorizationServicebooltrue to dispose of
authorizationServicewhen 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
authorizationServiceIAuthorizationServiceThe client proxy of the authorization service that this instance will wrap. This will be disposed (if it implements IDisposable) when this AuthorizationServiceClient is disposed.
ownsAuthorizationServicebooltrue to dispose of
authorizationServicewhen this instance is disposed; otherwise false.
Properties
AuthorizationService
Gets the authorization service client proxy.
public IAuthorizationService AuthorizationService { get; }
Property Value
IsDisposed
Gets a value indicating whether this instance has been disposed.
public bool IsDisposed { get; }
Property Value
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
operationProtectedOperationThe operation to check authorization for.
cancellationTokenCancellationTokenA 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
operationProtectedOperationThe operation to be performed.
cancellationTokenCancellationTokenA cancellation token.
Returns
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
cancellationTokenCancellationTokenA 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.