<rss version="2.0">
  <channel>
    <title>.NET Blog</title>
    <link>https://abudawood.me/net-blog</link>
    <description><![CDATA[]]></description>
    <item>
      <title>Configuration Steps to enable auto-generation client REST interfaces</title>
      <link>https://abudawood.me/net-blog/configuration-steps-to-enable-auto-generation-client-rest-interfaces</link>
      <description><![CDATA[<p style="margin-left: 0; text-align: justify"><strong>Problem Statement:</strong></p><p style="margin-left: 0; text-align: justify">In the process of developing a multi-layered RESTful system, which includes both backend and frontend components, there is a need to identify new endpoints and update existing ones. It is crucial that these updates are reflected in the RESTful client interface or API client proxy. However, the conventional approach involves manual implementation, resulting in numerous issues such as time wastage, inconsistencies between the API definitions and client representation, and a lack of documentation necessary for proper API utilization.</p><p style="margin-left: 0; text-align: justify"><strong>Proposition:</strong></p><p style="margin-left: 0; text-align: justify">We propose the implementation of a user-friendly auto-generation system that can simultaneously create a well-documented API client proxy. This solution will involve integrating third-party libraries, executing shell commands, and configuring Visual Studio settings.</p><p style="margin-left: 0; text-align: justify"><strong>Prerequisites:</strong></p><ol><li style="text-align: justify">Strongly defined API parameters, including data returned and input model schemas.</li><li style="text-align: justify">Strict adherence to RESTful conventions, utilizing HTTP methods to define actions and ensuring that endpoint URIs describe the affected elements.</li><li style="text-align: justify">Thorough documentation of the defined API.</li></ol><p style="margin-left: 0; text-align: justify"><strong>Methodology:</strong></p><ol><li style="text-align: justify">Enable XML documentation and incorporate it into the OpenAPI configuration.</li><li style="text-align: justify">Generate the OpenAPI as a physical JSON file during the project build process.</li><li style="text-align: justify">Use AutoRest to generate the API client in a specific output language (in this case, TypeScript) based on the generated OpenAPI JSON file.</li><li style="text-align: justify">Copy the commands derived from the previous steps into the post-build event.</li></ol><p style="margin-left: 0; text-align: justify"><strong>Explanation:</strong></p><p style="margin-left: 0; text-align: justify">In the API project properties, (1) enable the documentation file, and (2) specify the output XML filename and path.<br><img src="/media/autorest-media/ref1.png"><br>&nbsp;Source: <a href="https://exceptionnotfound.net/adding-swagger-to-asp-net-core-web-api-using-xml-documentation/">Adding Swagger to ASP.NET Core Web API Using XML Documentation</a></p><p style="margin-left: 0; text-align: justify">Include the on-build generated file in the Swagger configuration to make all documentation references appear in the Swagger UI.</p><p style="margin-left: 0; text-align: justify"><img src="/media/autorest-media/ref2.png"></p><p style="margin-left: 0; text-align: justify">Run the following commands to enable on-build Swagger JSON config file generation and set the path to the Web API project:</p><ul><li><strong>dotnet new tool-manifest</strong></li><li><strong>dotnet tool install --version 5.3.1 Swashbuckle.AspNetCore.Cli</strong> Source: <a href="https://medium.com/@woeterman_94/how-to-generate-a-swagger-json-file-on-build-in-net-core-fa74eec3df1">How to Generate a Swagger JSON File on Build in .NET Core</a></li></ul><p style="margin-left: 0; text-align: justify">To test JSON config file generation, run the following command:</p><ul><li><strong>dotnet swagger tofile --output swagger.json "bin\debug\net7.0\APIs.dll" v1</strong></li></ul><p style="margin-left: 0; text-align: justify">Install AutoRest using npm:</p><ul><li style="text-align: justify"><strong>npm install -g autorest</strong></li><li style="text-align: justify"><strong>autorest --latest</strong></li></ul><p style="margin-left: 0; text-align: justify">Generate the AutoRest client using the following command:</p><ul><li><strong>autorest --input-file=swagger.json --typescript --namespace=EarlyRegistration.APIs.Controllers --add-credentials</strong></li><li style="text-align: justify">If you encounter certification-related errors, try the following steps:<ul><li style="text-align: justify">Find and delete the file autorest.ps1 in "C:\Users%USERPROFILE%\AppData\Roaming\npm"</li><li style="text-align: justify">Execute the command: <strong>autorest --reset</strong></li></ul></li></ul><p style="margin-left: 0; text-align: justify">If the above steps work as expected, you can copy the commands to the post-build section in the Web API build properties. These commands include:</p><ul><li><strong>dotnet swagger tofile --output swagger.json "bin\debug\net7.0\APIs.dll" v1</strong></li><li><strong>autorest --input-file=swagger.json --output-folder=../../autogen-api-tsclient --typescript --namespace=EarlyRegistration.APIs.Controllers --add-credentials</strong></li></ul><p style="margin-left: 0; text-align: justify">Build your project, and in the file explorer, you should find a folder named "autogen-api-tsclient" located in the root folder of the project.</p>]]></description>
      <pubDate>Tue, 17 Oct 2023 08:30:50 GMT</pubDate>
      <guid isPermaLink="true">https://abudawood.me/net-blog/configuration-steps-to-enable-auto-generation-client-rest-interfaces</guid>
    </item>
    <item>
      <title>OpenID Connect and To Practice over ASP.NET Core</title>
      <link>https://abudawood.me/net-blog/openid-connect-and-to-practice-over-asp-net-core</link>
      <description><![CDATA[<p style="margin-left: 0; text-align: justify"><i><u>Please note that this is a draft for personal use, it misses some extended explanation and details, but I think it will be useful as an initial startup</u></i></p><h2 style="margin-left: 0; text-align: justify">1.&nbsp;&nbsp;&nbsp;Useful Resources with comments</h2><p style="margin-left: 0; text-align: justify">Recent trends for securing web APIs and Web Apps are dependent on the OAuth 2.0 with OpenID Connect protocols. Below are useful resources to understand the theory and the architecture. Additionally, some of them could help to implement Authentication and Authorization systems to secure ASP Core apps. The popular way is the utilization of Asp Core Identity with IdentityServer4.</p><h3 style="margin-left: 0; text-align: justify">1.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The official Microsoft documentation (Continuous)</h3><p style="margin-left: 0; text-align: justify">Make it your main handbook,</p><p style="margin-left: 0; text-align: justify">·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For Microsoft Identity check the link <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow">https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow</a></p><p style="margin-left: 0; text-align: justify">·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To review the security that is specific to ASP .NET Core check <a href="https://docs.microsoft.com/en-us/aspnet/core/security/?view=aspnetcore-5.0">https://docs.microsoft.com/en-us/aspnet/core/security/?view=aspnetcore-5.0</a></p><p style="margin-left: 0; text-align: justify">//TODO: put most important points related to ASP .NET Core API, such as Shared Cookies, Authorization, and Authentication...</p><h3 style="margin-left: 0; text-align: justify">1.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The Official IdentityServer4 Documentation (Continues)</h3><p style="margin-left: 0; text-align: justify"><a href="http://docs.identityserver.io/en/latest/index.html">http://docs.identityserver.io/en/latest/index.html</a></p><h3 style="margin-left: 0; text-align: justify">1.3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Introduction to understand the OAuth 2.0 and OpenID Connect</h3><p style="margin-left: 0; text-align: justify">It is important to have a clear definition of the OAuth and OpenID Connect (OIDC). Like many developers, they used them in the wrong way. To avoid such wrong definitions, check the links below:</p><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Remove fear by <a href="https://www.youtube.com/watch?v=t18YB3xDfXI">https://www.youtube.com/watch?v=t18YB3xDfXI</a> to gain a necessary terminology and nutshell explanation. You will also find some useful resources in the video description. You can also read this small article which I find useful <a href="https://nat.sakimura.org/2011/05/15/dummys-guide-for-the-difference-between-oauth-authentication-and-openid/">https://nat.sakimura.org/2011/05/15/dummys-guide-for-the-difference-between-oauth-authentication-and-openid/</a></p><p style="margin-left: 0; text-align: justify">&nbsp;</p><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For a deep review, I highly recommend starting with a video presented by Dr. Philippe De Ryck that mainly gave a clear definition for them and explained the different recommended flows for authentication and authorization. Notice that you should focus as much as you can to understand the different proposed flows, as they are essential to rich the highest levels of the security process for your apps</p><p style="margin-left: 0; text-align: justify">&nbsp;</p><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.youtube.com/watch?v=GyCL8AJUhww&amp;t=41s">Introduction to OAuth 2.0 and OpenID Connect • Philippe De Ryck • GOTO 2018</a></p><p style="margin-left: 0; text-align: justify">You can download the slides from the link <a href="https://www.youtube.com/redirect?event=video_description&amp;redir_token=QUFFLUhqbDJxR19PVzRxZzFHQUNTMklab0dMcFNPNXRxZ3xBQ3Jtc0tsbEY1OHo1c2R0NTFkQXVFaE1SRlBpdmN5SUg1dkMxU0VDb2ozYUhEVTB2OTVpVU04c3ZTYmZlT1NHMWhYTjJiQV9rWlJKdFhSZ3NRV19JZlZkcHZUSy0wSkFOeUxvZ21PRTRBZ1ZHQjBmMDF4MFVvYw&amp;q=https%3A%2F%2Fgotober.com%2F2018%2Fsessions%2F653">Slides</a> to extract the flows diagrams.</p><p style="margin-left: 0; text-align: justify">Also, you can watch another video for the same presenter that talks about the different API Security pitfalls <a href="https://www.youtube.com/watch?v=Ss1tZjooo9I">https://www.youtube.com/watch?v=Ss1tZjooo9I</a>.</p><h3 style="margin-left: 0; text-align: justify">1.3.1.&nbsp;&nbsp;&nbsp;&nbsp;Authentication and Authorization flow</h3><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Broad explanation given in <a href="https://auth0.com/docs/flows#authorization-code-flow-with-proof-key-for-code-exchange-pkce-">https://auth0.com/docs/flows#authorization-code-flow-with-proof-key-for-code-exchange-pkce-</a></p><h3 style="margin-left: 0; text-align: justify">1.4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpenID Connect and OAuth 2.0 specifically in ASP .NET Core</h3><h3 style="margin-left: 0; text-align: justify">1.4.1.&nbsp;&nbsp;&nbsp; <a href="https://andrewlock.net/an-introduction-to-openid-connect-in-asp-net-core/">An introduction to OpenID Connect in ASP.NET Core</a>: &nbsp;</h3><p style="margin-left: 0; text-align: justify">{Not well reviewed}</p><p style="margin-left: 0; text-align: justify"><a href="https://andrewlock.net/an-introduction-to-openid-connect-in-asp-net-core/">https://andrewlock.net/an-introduction-to-openid-connect-in-asp-net-core/</a></p><p style="margin-left: 0; text-align: justify">It also has some other useful links that may appear as a series of tutorials.</p><h3 style="margin-left: 0; text-align: justify">1.4.2.&nbsp;&nbsp;&nbsp; <a href="https://damienbod.com/2015/11/08/oauth2-implicit-flow-with-angular-and-asp-net-5-identity-server/">OAuth2 implicit flow with AngularJs and asp.net core 2.0 Identityserver4</a></h3><p style="margin-left: 0; text-align: justify">&nbsp;</p><p style="margin-left: 0; text-align: justify"><a href="https://damienbod.com/2015/11/08/oauth2-implicit-flow-with-angular-and-asp-net-5-identity-server/">https://damienbod.com/2015/11/08/oauth2-implicit-flow-with-angular-and-asp-net-5-identity-server/</a></p><p style="margin-left: 0; text-align: justify">It also has some other useful links that may appear as a series of tutorials.</p><h3 style="margin-left: 0; text-align: justify">1.4.3.&nbsp;&nbsp;&nbsp;&nbsp;IdentityServer 4 By Scott Brady &nbsp;</h3><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.scottbrady91.com/OAuth/Cheat-Sheet-OAuth-for-Browser-Based-Applications">https://www.scottbrady91.com/OAuth/Cheat-Sheet-OAuth-for-Browser-Based-Applications</a></p><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.scottbrady91.com/Identity-Server/Getting-Started-with-IdentityServer-4#Entity-Framework-Core">https://www.scottbrady91.com/Identity-Server/Getting-Started-with-IdentityServer-4#Entity-Framework-Core</a></p><p style="margin-left: 0; text-align: justify">&nbsp;</p><h3 style="margin-left: 0; text-align: justify">1.4.4.&nbsp;&nbsp;&nbsp;&nbsp;PART 1 IdentityServer4 ASP.NET Core Identity</h3><p style="margin-left: 0; text-align: justify"><a href="https://deblokt.com/2019/09/23/04-part-1-identityserver4-asp-net-core-identity/">https://deblokt.com/2019/09/23/04-part-1-identityserver4-asp-net-core-identity/</a></p><p style="margin-left: 0; text-align: justify">&nbsp;</p><h3 style="margin-left: 0; text-align: justify">1.5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Additional Terminologies</h3><h3 style="margin-left: 0; text-align: justify">1.5.1.&nbsp;&nbsp;&nbsp;&nbsp;Proof Key for Code Exchange (PKCE)</h3><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://auth0.com/docs/flows/authorization-code-flow-with-proof-key-for-code-exchange-pkce">https://auth0.com/docs/flows/authorization-code-flow-with-proof-key-for-code-exchange-pkce</a></p><h3 style="margin-left: 0; text-align: justify">1.5.2.&nbsp;&nbsp;&nbsp;&nbsp;Refresh Token</h3><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/">https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/</a></p><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://pragmaticwebsecurity.com/articles/oauthoidc/refresh-token-protection-implications.html">An in-depth look at refresh tokens in the browser</a></p><p style="margin-left: 0; text-align: justify">&nbsp;</p><h2 style="margin-left: 0; text-align: justify">2.&nbsp;&nbsp;&nbsp;Angular OIDC and OAuth 2.0 client</h2><h3 style="margin-left: 0; text-align: justify">2.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;angular-oauth2-oidc – used by ABP IO – seems awesome</h3><p style="margin-left: 0; text-align: justify"><a href="https://github.com/manfredsteyer/angular-oauth2-oidc">https://github.com/manfredsteyer/angular-oauth2-oidc</a></p><p style="margin-left: 0; text-align: justify">It has an official documentary in <a href="https://manfredsteyer.github.io/angular-oauth2-oidc/docs/index.html">https://manfredsteyer.github.io/angular-oauth2-oidc/docs/index.html</a>&nbsp;</p><p style="margin-left: 0; text-align: justify">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>Code Sample</strong> <a href="https://www.angulararchitects.io/aktuelles/authentication-in-angular-2-with-oauth2-oidc/">https://www.angulararchitects.io/aktuelles/authentication-in-angular-2-with-oauth2-oidc/</a></p><h3 style="margin-left: 0; text-align: justify">2.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;angular-auth-oidc-client</h3><p style="margin-left: 0; text-align: justify"><a href="https://github.com/damienbod/angular-auth-oidc-client">https://github.com/damienbod/angular-auth-oidc-client</a></p><h3 style="margin-left: 0; text-align: justify">2.3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oidc-client [seems old]</h3><p style="margin-left: 0; text-align: justify"><a href="https://github.com/IdentityModel/oidc-client-js">https://github.com/IdentityModel/oidc-client-js</a></p><p style="margin-left: 0; text-align: justify">used by Jason Taylor CleanCode Template but feel not recommended now</p><h2 style="margin-left: 0; text-align: justify">3.&nbsp;&nbsp;&nbsp;Additional Resources</h2><p style="margin-left: 0; text-align: justify"><a href="https://www.youtube.com/watch?v=SLc3cTlypwM">Authentication as a Microservice</a></p><p style="margin-left: 0; text-align: justify"><a href="https://auth0.com/docs/protocols/openid-connect-protocol">https://auth0.com/docs/protocols/openid-connect-protocol</a></p>]]></description>
      <pubDate>Tue, 15 Aug 2023 18:34:28 GMT</pubDate>
      <guid isPermaLink="true">https://abudawood.me/net-blog/openid-connect-and-to-practice-over-asp-net-core</guid>
    </item>
  </channel>
</rss>