ApiKey in Script Page as "nuxt" style parameter

My question: Is there a simpler way to do the following to populate the session in my case:

I have a simple script page that has a folder structure like: /billing/_token/index.html where token in my case is an api key (type billing that I’m restricting).

On the page I am sending the token to a service like this:

{{
 { apiKey: token} |> sendToGateway('BillingPageRequest') |> to => formData
}}

I noticed that the service does not create a session for the token when I do this so I checked the source code and was able to manually do it but am wondering if there is an automatic way so I don’t have to manually resolve the authprovider and call the preauthenticatewithapikey:

   var authProvider = (ApiKeyAuthProvider)
   AuthenticateService.GetAuthProvider(ApiKeyAuthProvider.Name);
   ApiKey key = new ApiKey() { Id=req.ApiKey, Environment="live", KeyType="billing"};
  authProvider.PreAuthenticateWithApiKey(base.Request, base.Response, key );
  // now i have a session and can get the userid


 [Route("/external/billing/{apiKey}")]
    public class BillingPageRequest
     {
         public string ApiKey {get;set;}
     }

PS You may want to rename this category from Templates to Sharp Script since Template was deprecated a while ago.

Can you try having your BillingPageRequest Request DTO implement IHasBearerToken and populating the BearerToken property instead.

1 Like

Worked perfectly, thank you.

1 Like