Arc4u.Standard.OAuth2.AspNetCore 8.2.0

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Arc4u.Standard.OAuth2.AspNetCore --version 8.2.0                
NuGet\Install-Package Arc4u.Standard.OAuth2.AspNetCore -Version 8.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Arc4u.Standard.OAuth2.AspNetCore" Version="8.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Arc4u.Standard.OAuth2.AspNetCore --version 8.2.0                
#r "nuget: Arc4u.Standard.OAuth2.AspNetCore, 8.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Arc4u.Standard.OAuth2.AspNetCore as a Cake Addin
#addin nuget:?package=Arc4u.Standard.OAuth2.AspNetCore&version=8.2.0

// Install Arc4u.Standard.OAuth2.AspNetCore as a Cake Tool
#tool nuget:?package=Arc4u.Standard.OAuth2.AspNetCore&version=8.2.0                

Arc4u.Standard.OAuth2.AspNetCore

Core framework to integrate OAuth2 and creation of the principal in asp net core.

As it is a AspNetCore library, it is based on the Microsoft.AspNetCore.Authentication and Microsoft.AspNetCore.Authentication.OAuth libraries.

Do not use this package in other contexts than AspNetCore.

ProblemDetails extension

When working with the Results feature in Arc4u, the Rest Api controller will return a ProblemDetails object when an error occurs.

The idea is from a controller endpoint to call the business layer and return the result to the client. The business layer will return a Result object that can be converted to an ActionResult object.

    return await bl.DoSomethingAsync()
                   .ToActionOkResultAsync();

Different situations, different HttpStatusCodes can be returned.

Success path:

When the call to the business layer is a success, depending on the result, different codes will be returned.

Result:

The return code is 204 NoContent.

Result<T>

The return code is 200 Ok or 201 Created.

200 Ok HTTP GET

What to return when the value is null?
On internet, it is not clear what to return when the value is null. Some say to return a 204 NoContent, others say to return a 200 OK with a null value.
I find personaly than returning a 204 NoContent is more appropriate. The client knows that the call was successful but there is no content to return.

If you are using proxy code generator like NSwagStudio, this situation is not managed like I would expect. If you return a 200 Ok when you have a value and a 204 NoContent when the value is null, the proxy code generator will return the value when there is a value but will manage the 204 NoContent as an error! To avoid this today, I return a 200 Ok with a null value. The client will have to manage the null value.

It is possible to override the default behavior by informing the extension method to return another code when the value is null.

    return await bl.DoSomethingAsync(id)
                   .ToActionResultAsync(() => StatusCode(StatusCodes.Status204NoContent));

Mapping to a Dto is also possible. The mapper is a function and can be AutoMapper or any other mapper.

    return await bl.DoSomethingAsync(id)
                   .ToActionResultAsync(mapper.Map<ContractDto>);
201 Created HTTP POST

When the result is a 201 Created, the location header is set to the location of the created resource.

To handle this specific situation, the extension method ToActionCreatedResultAsync is available. The method expect a Uri to set the location correctly.
The need to split the call in two steps is to allow the business layer to return the result and the controller to set the location header.
If you do this in one step, the location is captured when the fluent Api is built and the location will never be updated when the ToActionCreatedResultAction is called!


        Uri? location = null;

        var result = await bl.DoSomethingAsync(dto, cancellation)
                                         .OnSuccess((contract) => location = new Uri(Url.ActionLink("GetById", "Contract", new { id = contract.Id })!))
                                         .ConfigureAwait(false);

        return await result.ToActionCreatedResultAsync(location, mapper.Map<ContractDto>)
                           .ConfigureAwait(false);

Error path:

When an error occurs, the business layer will return a Result object with the error information.

Different cases could happen:

  • An exception was thrown.
  • A validation error occured.
  • A Problem occured.
Exception

When an exception is thrown, a 500 InternalServerError is returned with a ProblemDetails message explaining that the exception is log with an activyId. There is no more explanation about the exception to avoid leaking information.

Validation error

When some parameters or Dto is given to a controller, code will validate the inputs.
If the validation fails, a 422 UnprocessableEntity is returned with a ValidationProblemDetails message explaining the validation errors.
The code of the validation error is used to categorrized the errors (they are grouped by code).

Problem

When a problemDetailError is returned, a 500 InternalServerError is returned with a ProblemDetails message explaining the error when no specific StatusCode is given.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Arc4u.Standard.OAuth2.AspNetCore:

Package Downloads
Arc4u.Standard.OAuth2.AspNetCore.Msal

Core Framework used in AspNetCore to authenticate user based on Msal.

Arc4u.Standard.OAuth2.AspNetCore.Adal

Package Description

Arc4u.Standard.OAuth2.AspNetCore.Authentication

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.3.0-preview01 100 8/30/2024
8.2.0 435 8/16/2024
8.2.0-preview31 127 8/16/2024
8.2.0-preview30 145 8/1/2024
8.2.0-preview29 59 7/25/2024
8.2.0-preview28 63 7/25/2024
8.2.0-preview27 126 6/28/2024
8.2.0-preview26 117 6/27/2024
8.2.0-preview25 114 6/26/2024
8.2.0-preview24 117 6/9/2024
8.2.0-preview23 198 5/29/2024
8.2.0-preview22 127 5/26/2024
8.2.0-preview21 119 5/22/2024
8.2.0-preview20 131 5/19/2024
8.2.0-preview19 90 5/18/2024
8.2.0-preview18 90 5/12/2024
8.2.0-preview17 80 5/12/2024
8.2.0-preview16 73 5/12/2024
8.2.0-preview15 78 5/11/2024
8.2.0-preview14 82 5/10/2024
8.2.0-preview13 73 5/9/2024
8.2.0-preview12 99 5/8/2024
8.2.0-preview11 129 5/7/2024
8.2.0-preview10 122 5/5/2024
8.2.0-preview09 113 5/4/2024
8.2.0-preview08 104 4/25/2024
8.2.0-preview07 123 4/23/2024
8.2.0-preview06 112 4/23/2024
8.2.0-preview05 96 4/21/2024
8.2.0-preview04 98 4/20/2024
8.2.0-preview03 90 4/17/2024
8.2.0-preview02 125 4/12/2024
8.2.0-preview01 125 4/11/2024
8.1.0 679 2/7/2024
8.1.0-preview10 103 2/6/2024
8.1.0-preview09 107 1/29/2024
8.1.0-preview08 162 1/9/2024
8.1.0-preview07 162 12/31/2023
8.1.0-preview06 121 12/30/2023
8.1.0-preview05 126 12/24/2023
8.1.0-preview04 122 12/23/2023
8.1.0-preview03 123 12/20/2023
8.1.0-preview02 135 12/20/2023
8.1.0-preview01 136 12/19/2023
8.0.0 211 12/15/2023
8.0.0-preview01 123 12/14/2023
6.1.22.1-preview06 171 11/25/2023
6.1.22.1-preview05 117 11/24/2023
6.1.22.1-preview04 144 11/20/2023
6.1.22.1-preview03 136 11/17/2023
6.1.22.1-preview02 108 11/17/2023
6.1.22.1-preview01 99 11/16/2023
6.1.21.1-preview04 102 10/10/2023
6.1.21.1-preview03 91 10/10/2023
6.1.21.1-preview02 87 10/5/2023
6.1.21.1-preview01 89 9/21/2023
6.1.20.1-preview03 96 8/31/2023
6.1.20.1-preview02 162 8/14/2023
6.1.20.1-preview01 131 8/13/2023
6.1.18.1 440 8/18/2023
6.0.14.3-preview56 144 8/7/2023
6.0.14.3-preview55 125 8/4/2023
6.0.14.3-preview54 151 8/3/2023
6.0.14.3-preview53 158 8/1/2023
6.0.14.3-preview52 146 7/26/2023
6.0.14.3-preview51 170 7/26/2023
6.0.14.3-preview50 151 7/19/2023
6.0.14.3-preview49 132 7/19/2023
6.0.14.3-preview48 162 7/12/2023
6.0.14.3-preview47 155 7/6/2023
6.0.14.3-preview46 146 7/3/2023
6.0.14.3-preview45 147 6/24/2023
6.0.14.3-preview44 159 6/18/2023
6.0.14.3-preview43 135 6/18/2023
6.0.14.3-preview42 132 6/14/2023
6.0.14.3-preview41 144 6/12/2023
6.0.14.3-preview40 144 6/9/2023
6.0.14.3-preview39 139 6/8/2023
6.0.14.3-preview38 134 5/30/2023
6.0.14.3-preview37 164 5/29/2023
6.0.14.3-preview36 162 5/26/2023
6.0.14.3-preview35 154 5/23/2023
6.0.14.3-preview34 138 5/22/2023
6.0.14.3-preview33 155 5/19/2023
6.0.14.3-preview32 157 5/19/2023
6.0.14.3-preview31 153 5/18/2023
6.0.14.3-preview30 155 5/12/2023
6.0.14.3-preview29 152 5/12/2023
6.0.14.3-preview28 134 5/10/2023
6.0.14.3-preview27 160 5/8/2023
6.0.14.3-preview26 166 5/7/2023
6.0.14.3-preview25 161 5/3/2023
6.0.14.3-preview24 165 4/29/2023
6.0.14.3-preview23 162 4/28/2023
6.0.14.3-preview22 136 4/27/2023
6.0.14.3-preview21 150 4/26/2023
6.0.14.3-preview20 153 4/24/2023
6.0.14.3-preview19 157 4/18/2023
6.0.14.3-preview18 150 4/17/2023
6.0.14.3-preview17 176 4/16/2023
6.0.14.3-preview16 118 4/14/2023
6.0.14.3-preview15 157 4/14/2023
6.0.14.3-preview14 155 4/11/2023
6.0.14.3-preview13 191 4/3/2023
6.0.14.3-preview12 142 4/1/2023
6.0.14.3-preview11 162 4/1/2023
6.0.14.3-preview10 155 3/30/2023
6.0.14.3-preview09 147 3/29/2023
6.0.14.3-preview08 176 3/25/2023
6.0.14.3-preview07 157 3/24/2023
6.0.14.3-preview06 157 3/19/2023
6.0.14.3-preview05 159 3/17/2023
6.0.14.3-preview04 144 3/15/2023
6.0.14.3-preview03 126 3/15/2023
6.0.14.3-preview02 158 3/14/2023
6.0.14.3-preview01 130 3/11/2023
6.0.14.2 920 3/8/2023
6.0.14.2-preview02 151 3/4/2023
6.0.14.2-preview01 139 3/3/2023
6.0.14.1 391 2/17/2023
6.0.14.1-preview02 158 2/16/2023
6.0.14.1-preview01 156 2/15/2023
6.0.13.1 375 2/15/2023
6.0.12.1 396 2/15/2023
6.0.11.2 385 2/15/2023
6.0.11.2-preview03 140 2/14/2023
6.0.11.2-preview02 150 2/13/2023
6.0.11.2-preview01 154 2/12/2023
6.0.11.1 2,391 1/11/2023
6.0.11.1-preview11 155 1/10/2023
6.0.11.1-preview10 149 1/10/2023
6.0.11.1-preview09 177 1/8/2023
6.0.11.1-preview08 177 1/4/2023
6.0.11.1-preview07 161 1/3/2023
6.0.11.1-preview06 152 1/3/2023
6.0.11.1-preview05 163 1/2/2023
6.0.11.1-preview04 144 1/2/2023
6.0.11.1-preview03 126 12/10/2022
6.0.11.1-preview02 139 11/15/2022
6.0.11.1-preview01 264 11/11/2022
6.0.9.3 3,077 11/8/2022
6.0.9.2 711 9/27/2022
6.0.9.1 4,075 9/17/2022
6.0.8.4 607 11/8/2022
6.0.8.3 761 9/27/2022
6.0.8.2 585 9/16/2022
6.0.8.1 580 9/7/2022
6.0.8.1-preview02 146 9/5/2022
6.0.8.1-preview01 164 8/18/2022
6.0.6.1-preview03 199 6/25/2022
6.0.6.1-preview02 168 6/15/2022
6.0.6.1-preview01 138 6/15/2022
6.0.5.1-preview01 414 5/10/2022
6.0.4.1-preview04 175 5/7/2022
6.0.4.1-preview03 188 4/27/2022
6.0.4.1-preview02 159 4/27/2022
6.0.4.1-preview01 166 4/24/2022
5.0.17.3 677 9/19/2022
5.0.17.3-preview01 206 9/16/2022
5.0.17.2 626 9/1/2022
5.0.17.2-preview07 161 8/29/2022
5.0.17.2-preview06 161 8/24/2022
5.0.17.2-preview05 158 8/24/2022
5.0.17.2-preview04 126 8/23/2022
5.0.17.2-preview03 157 8/22/2022
5.0.17.2-preview02 143 8/22/2022
5.0.17.2-preview01 150 8/17/2022
5.0.17.1 670 5/30/2022
5.0.16.1 673 5/7/2022
5.0.16.1-preview02 185 4/17/2022
5.0.16.1-preview01 170 4/14/2022
5.0.15.1-preview07 176 4/2/2022
5.0.15.1-preview06 158 4/1/2022
5.0.15.1-preview05 153 3/30/2022
5.0.15.1-preview04 186 3/27/2022
5.0.15.1-preview03 155 3/18/2022
5.0.15.1-preview02 179 3/13/2022
5.0.15.1-preview01 170 3/13/2022
5.0.14.1-preview9 158 3/1/2022
5.0.14.1-preview7 167 2/23/2022
5.0.14.1-preview6 181 2/20/2022
5.0.14.1-preview5 166 2/20/2022
5.0.14.1-preview4 156 2/19/2022
5.0.14.1-preview3 180 2/19/2022
5.0.14.1-preview2 175 2/10/2022
5.0.14.1-preview13 146 3/11/2022
5.0.14.1-preview12 176 3/9/2022
5.0.14.1-preview11 178 3/7/2022
5.0.14.1-preview10 172 3/2/2022
5.0.14.1-preview1 176 2/9/2022
5.0.13.1-preview4 194 1/30/2022
5.0.13.1-preview3 175 1/29/2022
5.0.13.1-preview2 186 1/29/2022
5.0.13.1-preview1 179 1/29/2022
5.0.11.2 2,144 10/20/2021
5.0.11.2-preview1 247 10/19/2021
5.0.11.1 466 10/19/2021
5.0.11.1-preview4 228 10/19/2021
5.0.11.1-preview3 278 10/18/2021
5.0.11.1-preview2 269 10/17/2021
5.0.11.1-preview1 253 10/16/2021
5.0.10.3 498 9/30/2021
5.0.10.2 554 9/30/2021
5.0.10.1 498 9/28/2021
5.0.9.1-preview1 226 9/1/2021
5.0.8.2 340 8/19/2021
5.0.8.1 356 8/11/2021
5.0.6.4 404 7/13/2021
5.0.6.3 890 7/10/2021
5.0.6.2 344 7/7/2021
5.0.6.1 813 6/29/2021
5.0.6.1-rc16 259 6/21/2021
5.0.6.1-rc15 256 6/20/2021
5.0.6 2,033 5/21/2021
5.0.5 403 5/21/2021
1.0.0 124 5/18/2024