DEV Community

Ghassan Karwchan
Ghassan Karwchan

Posted on

2

Parse Azure SAS token using regular expression

If you have an Azure SAS token that is not working, it is good idea to parse it and understand what permissions and values it contains.

This is a JavaScript code that uses Regular Expression to parse he SAS token, and an running example where you can try your own SAS token.

var paramNames = {
  sig: 'cryptographic signature',
  st: 'start time',
  se: 'end time',
  spr: 'protocol',
  srt: 'resource types',
  sv: 'version',
  sp: 'permissions',
  ss: 'services'
};

let valueLookups = {
  sp : {
     r: 'read', d: 'delete', w: 'write', l: 'list', a: 'add',
    c: 'create', u: 'update', p: 'process', f: 'filter'
    },
  srt: {
    s: 'service', c: 'container', o: 'object'
  },
  ss : {
    b: 'blob', f: 'file', q: 'queue', t: 'table'
  }
}

let valueConvertor = (key, inputValue) => 
      valueLookups[key] ? [...inputValue].map(x => valueLookups[key][x] || x)
        : inputValue;

function parseData(sasToken) {
  let regExpressionPattern = /[?&]([a-z]*)=([^\&]*)/g;
  var parameters = [...sasToken.matchAll(regExpressionPattern)];
const finalObject = parameters.reduce((acc, row) => {
  return {...acc, [paramNames[row[1]] || row[1]]: valueConvertor(row[1], row[2])}
}, {});


var outputObject = ParseData(inputSasToken);

// The output object will be in the format
{
  "version":"2021-06-08",
  "services":["blob","file","queue","table"],
  "resource types":["service","container","object"],
  "permissions":["read","write","delete","list","add","create","update","process","i","y","t","filter","x"],
  "end time":"2023-02-04T03:03:37Z",
  "start time":"2023-02-03T19:03:37Z",
  "protocol":"https",
  "cryptographic signature":"..jhh"
}

Enter fullscreen mode Exit fullscreen mode

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay