Skip to content

Auto-refresh JWT tutorial #362

@Sytten

Description

@Sytten

Summary of the gap

Helping a user understand how to use the convert workflow and environment variables to setup an auto-refresh JWT for replay.

What is the goal of this content?

Learning: A step-by-step tutorial for beginners.

Success Criteria

A user should be able to create their own workflow to refresh their JWT (usually probably a fetch in the JS node), store the result in the environment and inject in a placeholder of replay.

Technical Details / Proposed Content

import { Request as FetchRequest, fetch } from "caido:http";

export function run({ data }, sdk) {
   let jwt = sdk.env.getVar("MY_SECRET");
   const valid = false; // Check if still valid
   if (!valid) {
     // Refresh logic
     const fetchRequest = new FetchRequest("https://google.com");
     const resp = await fetch(fetchRequest);
     const body = await resp.json();
     await sdk.env.setVar("MY_SECRET", body.access_token);
     jwt = body.access_token;
   }
   return jwt;
}

See Also

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions