Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stefh/restease.authentication.azure
Add AzureAd Authentication for RestEase: the easy-to-use typesafe REST API client library.
https://github.com/stefh/restease.authentication.azure
Last synced: 19 days ago
JSON representation
Add AzureAd Authentication for RestEase: the easy-to-use typesafe REST API client library.
- Host: GitHub
- URL: https://github.com/stefh/restease.authentication.azure
- Owner: StefH
- License: mit
- Created: 2022-01-20T15:07:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-20T16:33:46.000Z (about 1 year ago)
- Last Synced: 2024-04-14T13:08:18.297Z (7 months ago)
- Language: C#
- Size: 41 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Project Icon](icon.png) RestEase.Authentication.Azure
==================================An extension to [RestEase](https://github.com/canton7/RestEase) which adds AzureAd Authentication.
Supported modes are:
- Client with ClientSecret
- Managed Identity## Install
[![NuGet Badge](https://buildstats.info/nuget/RestEase.Authentication.Azure)](https://www.nuget.org/packages/RestEase.Authentication.Azure)You can install from NuGet using the following command in the package manager window:
`Install-Package RestEase.Authentication.Azure`
Or via the Visual Studio NuGet package manager or if you use the `dotnet` command:
`dotnet add package RestEase.Authentication.Azure`
### Configuration when using a ClientId + ClientSecret
#### appsettings.json
``` json
{
"DocumentApiClientOptions": {
"TenantId": "t",
"ClientId": "c",
"ClientSecret": "s",
"Resource": "r",
"BaseAddress": "https://localhost:44318",
"AcceptAnyServerCertificate": true,
"TimeoutInSeconds": 99
}
}
```### Configuration when using a Managed Identity with a ClientId
#### appsettings.json
``` json
{
"DocumentApiClientOptions": {
"ClientId": "c",
"Resource": "r",
"BaseAddress": "https://localhost:44318",
"AcceptAnyServerCertificate": true,
"TimeoutInSeconds": 99
}
}
```### Configuration when using a Managed Identity without a ClientId (it will fall back to DefaultAzureCredential)
#### appsettings.json
``` json
{
"DocumentApiClientOptions": {
"Resource": "r",
"BaseAddress": "https://localhost:44318",
"AcceptAnyServerCertificate": true,
"TimeoutInSeconds": 99
}
}
```:information_source: If the `scopes`-array is not defined, the default the scope `{Resource}/.default` is used.
### Usage
#### :one: Create a RestEase interface
``` csharp
[BasePath("/api")]
public interface IDocumentApi
{
[Get("GetDocumentById/{id}")]
Task> GetDocumentAsync([Path] int id, CancellationToken cancellationToken = default);
}
```#### :two: Configure Dependency Injection
``` csharp
services.UseWithAzureAuthenticatedRestEaseClient(configuration.GetSection("DocumentApiClientOptions"));
```#### :three: Use it in your code
``` csharp
IDocumentApi documentApi = ...; // Injected
var document = await documentApi.GetDocumentAsync(1, cancellationToken);
```