Layer7 API Management

 View Only
  • 1.  Get a short token

    Posted Jul 22, 2020 11:11 AM
    Hello,
    how can you get a token that is less than 100 characters long?

    Alternatively, is there an assertion, or a workaround, to shorten a url?

    Thanks,
    Alfredo


  • 2.  RE: Get a short token

    Broadcom Employee
    Posted Jul 22, 2020 11:27 AM
    Hi Alfredo,

    If you are referring to an OAuth token, these default to using a UUID value as an access token which is less than 100 characters.
    As far as shortening a URL, I may need a bit more context for what you are trying to accomplish. Your services and URL are defined by you during creation.

    Are you looking to shorten other URLs like that of OTK or some other build-in / add-on service? If you can provide some more detail I am happy to look into this more for you.

    Regards,
    Joe


  • 3.  RE: Get a short token
    Best Answer

    Posted Jul 23, 2020 03:57 AM

    Hello Alfredo,

    If you want to generate a new token that is less than 100 characters long, you can use the "Generate UUID" assertion or the JavaScript assertion. With the last one you can perform more flexible transformations. I have included a sample JS code for the JavaScript assertion that you can use as a basis and replace the "generateRandomString" function with your new function/s to archive your goal. 

    regards,

    Oleks

    //beginning of the JS-Code:

    if (typeof context !== 'undefined') {
    // this part of code is executed in GW
    // the GW variable is defined
    try {
    var sessionId = generateRandomString();
    context.setVariable('sessionId', sessionId);

    } catch (err) {
    context.setVariable('ErrorJS', err);
    }
    } else {
    // for execution in a third JS tool for easiert testing
    var sessionId = generateRandomString();
    console.log('sessionId', sessionId);
    }


    function generateRandomString() {
    return Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10);
    }




  • 4.  RE: Get a short token

    Posted Jul 24, 2020 04:40 AM
    Hello,
    thanks to your help now I have a first draft, that's better than nothing.

    I'm going to show you the issue with more details:

    I have a POST call to the API Gateway, with an id called MyID of 36 characters, in the body of request:

    eg. www.myl7.com/generate_token 
    In the body of the request there is {MyID: 123456789-123456789-123456789-123456}

    I have to encrypt the MyID, but the result has to be less than 100 characters.

    With Base64 encoding assertion the length is ok, but it is just encoded and not encrypted.

    How can I encrypt it in a string that is less than 100 carachters?

    Thanks,
    Alfredo