<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rafaela Nascimento Carvalho</title>
    <description>The latest articles on DEV Community by Rafaela Nascimento Carvalho (@rafaelanasciment).</description>
    <link>https://dev.to/rafaelanasciment</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1175015%2Fcee3c988-9f44-4b16-ad2b-582d77a44c50.jpeg</url>
      <title>DEV Community: Rafaela Nascimento Carvalho</title>
      <link>https://dev.to/rafaelanasciment</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rafaelanasciment"/>
    <language>en</language>
    <item>
      <title>JWT - BEARER TOKEN</title>
      <dc:creator>Rafaela Nascimento Carvalho</dc:creator>
      <pubDate>Tue, 09 Jan 2024 19:54:22 +0000</pubDate>
      <link>https://dev.to/rafaelanasciment/jwt-bearer-token-3ndc</link>
      <guid>https://dev.to/rafaelanasciment/jwt-bearer-token-3ndc</guid>
      <description>&lt;p&gt;O &lt;strong&gt;JSON Web Token&lt;/strong&gt; (JWT) é uma maneira segura de transmitir informações entre partes. Ele é frequentemente usado para autenticação em sistemas web e troca de informações entre serviços. Vamos simplificar:&lt;/p&gt;

&lt;p&gt;Imagine que você tem uma "caixa" (token) que contém informações importantes. Essa caixa é assinada digitalmente para garantir que ninguém mexeu com ela. Dentro dessa caixa, você coloca algumas informações, como quem é o usuário e por quanto tempo o token é válido.&lt;/p&gt;

&lt;p&gt;Quando você precisa compartilhar essas informações com outro serviço, você entrega a "caixa" (token). O serviço receptor pode verificar a assinatura para garantir que o conteúdo não foi alterado e, assim, confiar nas informações dentro do token.&lt;/p&gt;

&lt;p&gt;Portanto, JWT é como uma caixa segura que você pode enviar para outros serviços, e eles podem confiar nas informações nela devido à assinatura digital. Isso é muito útil para autenticação e autorização em aplicações web.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configurações&lt;/strong&gt;&lt;br&gt;
Instalar o pacote Microsoft.AspNetCore.Authentication.JwtBearer&lt;br&gt;
Chave secreta = para gerar o token é necessário informar uma chave secreta, que deve ter no minimo 128 bits, por segura é importante remove-la do código, mas em período de teste é possível adiciona-lá no appSettings ou em uma classe apoio, conforme o exemplo abaixo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5M6f-V_k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5h6o28tekbcwbrebfdc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5M6f-V_k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5h6o28tekbcwbrebfdc.png" alt="Image description" width="800" height="94"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Estrutura do JWT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Handler - Cria uma instancia do JWT - Principal responsável pela geração do token (através dele o token será gerado)&lt;br&gt;
Inicialização:&lt;br&gt;
var handler = new JwtSecurityTokenHandler()&lt;/p&gt;

&lt;p&gt;CreateToken - Método responsável pela criação do token, a partir dos parametros informados no tokenDescriptor.&lt;br&gt;
var token = handler.CreateToken(tokenDescriptor);&lt;/p&gt;

&lt;p&gt;WriteToken - Conversão do token para string.&lt;br&gt;
var strToken = handler.WriteToken(token);&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I2LcDDy5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uif7xfkr6cahwrgky2eo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I2LcDDy5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uif7xfkr6cahwrgky2eo.png" alt="Image description" width="723" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-- Configurando as credencias&lt;br&gt;
SigningCredentials - Responsável pelas credenciais que serão utilizadas na criação do token - Objeto utilizado para realizar a assinatura do token&lt;br&gt;
var key = Encoding.ASCII.GetBytes(Configuration.PrivateKey);&lt;br&gt;
var credentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature);&lt;/p&gt;

&lt;p&gt;TokenDescriptor - Conteúdo que ficará dentro do token e será criptografado.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xrb6GQQ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upt6640n6csnlt30rntx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xrb6GQQ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upt6640n6csnlt30rntx.png" alt="Image description" width="800" height="266"&gt;&lt;/a&gt;&lt;br&gt;
~~Aproximado&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IyU4DXvI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vr653lc47sk8ql79r49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IyU4DXvI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vr653lc47sk8ql79r49.png" alt="Image description" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;É possivel configurar o tempo de expiração do token, para aumentar a segurança, conforme mostra abaixo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dUP_1ehJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqr74qyo2j61cirgiol9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dUP_1ehJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqr74qyo2j61cirgiol9.png" alt="Image description" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Projetos criados que utilizam o token JWT:&lt;br&gt;
&lt;a href="https://github.com/RafaelaNasciment/carrinho-compras"&gt;https://github.com/RafaelaNasciment/carrinho-compras&lt;/a&gt; &lt;br&gt;
&lt;a href="https://github.com/RafaelaNasciment/JwtBearer"&gt;https://github.com/RafaelaNasciment/JwtBearer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conteúdos utilizados para desenvolvimento desse artigo: &lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=-eGSRK7z8-w"&gt;https://www.youtube.com/watch?v=-eGSRK7z8-w&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=anjAu3RY7o8"&gt;https://www.youtube.com/watch?v=anjAu3RY7o8&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  jwt #csharp #development #auth #authorization
&lt;/h1&gt;

</description>
    </item>
    <item>
      <title>Unit teste - Triple A (AAA)</title>
      <dc:creator>Rafaela Nascimento Carvalho</dc:creator>
      <pubDate>Mon, 30 Oct 2023 00:31:57 +0000</pubDate>
      <link>https://dev.to/rafaelanasciment/unit-teste-triple-a-aaa-2ci7</link>
      <guid>https://dev.to/rafaelanasciment/unit-teste-triple-a-aaa-2ci7</guid>
      <description>&lt;p&gt;Model used when creating tests&lt;/p&gt;

&lt;p&gt;Arrange -&amp;gt; Configuration of the information necessary to run the tests.&lt;/p&gt;

&lt;p&gt;Act -&amp;gt; Calling the methods configured in the first step to execute the test&lt;/p&gt;

&lt;p&gt;Assert -&amp;gt; It is the test verification. This is the part where we inform what method will be used to validate the test and whether the expected result was achieved.&lt;/p&gt;

&lt;p&gt;Consultation material: &lt;a href="https://medium.com/@pablodarde/o-padr%C3%A3o-triple-a-arrange-act-assert-741e2a94cf88"&gt;https://medium.com/@pablodarde/o-padr%C3%A3o-triple-a-arrange-act-assert-741e2a94cf88&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;example code using .net 7: &lt;a href="https://github.com/RafaelaNasciment/UnitTestExample"&gt;https://github.com/RafaelaNasciment/UnitTestExample&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--35uUB2xZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ogn8ldyc61vpmc462wno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--35uUB2xZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ogn8ldyc61vpmc462wno.png" alt="Image description" width="499" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tdd</category>
      <category>dotnet</category>
      <category>backend</category>
      <category>unittest</category>
    </item>
    <item>
      <title>TDD -&gt; Test Driven Development</title>
      <dc:creator>Rafaela Nascimento Carvalho</dc:creator>
      <pubDate>Mon, 30 Oct 2023 00:17:11 +0000</pubDate>
      <link>https://dev.to/rafaelanasciment/tdd-test-driven-development-3m46</link>
      <guid>https://dev.to/rafaelanasciment/tdd-test-driven-development-3m46</guid>
      <description>&lt;p&gt;It is a development approach, where the objective is to start testing before code.&lt;/p&gt;

&lt;p&gt;TDD's timeline&lt;/p&gt;

&lt;p&gt;Red &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the test visualizing the final objective. Ex: create a profile, the test must cover the process until the end.&lt;/li&gt;
&lt;li&gt;At this stage the test must fail.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Green&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The implementation of the code begins, which must be developed until the test created in the RED stage is stabilized. &lt;/li&gt;
&lt;li&gt;At this stage the test must be successful.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Refactor &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The code must be refactored to improve quality and clarity.&lt;/li&gt;
&lt;li&gt;At this stage the test must be successful.
Support material:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=NxTgE4rx9uk"&gt;https://www.youtube.com/watch?v=NxTgE4rx9uk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=bLdEypr2e-8&amp;amp;t=405s"&gt;https://www.youtube.com/watch?v=bLdEypr2e-8&amp;amp;t=405s&lt;/a&gt; &lt;/p&gt;

</description>
      <category>tdd</category>
      <category>unittest</category>
      <category>backenddevelopment</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
