title: How to pass the value to the AuthenticationProvider from HttpRequest in Micronaut java with Jnunit 5
body: <p>Using Micronaut HttpClient to perform the HTTP calls in Junit 5 testing.</p>
  <p>I am trying to pass the value to AuthenticationProvider using HttpRequest as below</p>
  <pre><code>@MicronautTest
  public class ProductCreateTest extends TestContainerFixture {
  
      @Inject
      @Client(&quot;/&quot;)
      HttpClient client;
  
  
      @Test
      @DisplayName(&quot;Should create the product&quot;)
      void shouldCreateTheProduct() {
          HttpRequest request = HttpRequest.POST(&quot;/product&quot;, new ProductModel())
              .bearerAuth(bearerAccessRefreshToken.getAccessToken());
          request.setAttribute(&quot;fb_product&quot;, &quot;owner&quot;);
          HttpResponse &lt; ProductModel &gt; rsp = client.toBlocking().exchange(request, ProductModel.class);
          var item = rsp.body();
      }
  }
  </code></pre>
  <p>Here I am setting an attribute as <code>request.setAttribute(&quot;fb_product&quot;, &quot;owner&quot;);</code> and in the authentication provider I am trying to access the attribute as below</p>
  <p><a href="https://i.stack.imgur.com/HI0Sh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HI0Sh.png" alt="enter image description here" /></a></p>
  <pre><code>@Singleton
  @Requires(env = Environment.TEST)
  public record AuthenticationProviderFixture(Configuration configuration) implements AuthenticationProvider {
      @Override
      public Publisher&lt;AuthenticationResponse&gt; authenticate(HttpRequest&lt;?&gt; httpRequest, AuthenticationRequest&lt;?, ?&gt; authenticationRequest) {
          return Flux.create(emitter -&gt; {
              if (authenticationRequest.getIdentity().equals(configuration.Username()) &amp;&amp; authenticationRequest.getSecret().equals(configuration.Password())) {
                  var attributeValue = httpRequest.getAttribute(&quot;fb_product&quot;);
                  HashMap&lt;String, Object&gt; attributes = new HashMap&lt;&gt;();
                  emitter.next(AuthenticationResponse.success((String) authenticationRequest.getIdentity(), attributes));
                  emitter.complete();
              } else {
                  emitter.error(AuthenticationResponse.exception());
              }
          }, FluxSink.OverflowStrategy.ERROR);
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Qnqex.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qnqex.png" alt="enter image description here" /></a></p>
  <p>The attribute is not mapped and this provides an null value <code>var attributeValue = httpRequest.getAttribute(&quot;fb_product&quot;);</code></p>
  <p>What is the best approach to pass the data from HttpRequest to AuthenticationProvider</p>
  <p>There is a concept of the token generator, however, with the token generator on the security rule, the authentication is null.</p>
  <p>Inject the <code>TokenGenerator</code> and create a token</p>
  <pre><code>Map&lt;String, Object&gt; claims = new HashMap&lt;&gt;();
          claims.put(&quot;fb_product&quot;,&quot;owner&quot;);
          var claimGenerator = tokenGenerator.generateToken(claims);
  </code></pre>