Skip to main content
Community site session details

Community site session details

Session Id :

Parse a bearer token using Flow

svarukala Profile Picture Posted by svarukala Microsoft Employee

A simple button (manual) flow that can parse a bearer token to extract details like:

  • Issuer
  • AppID
  • Audience
  • TokenSubject
  • TokenSender etc.

Note that a HTTP based flow won't execute when you pass a bearer token in the Authorization header. You can send it as a normal POST body or a parameter instead and use that as a layer of security so that Flow can validate the token and only then execute.

Categories:

Comments

  • vincenzos1984_1 Profile Picture vincenzos1984_1 117
    Posted at
    Parse a bearer token using Flow

    thanks a lot solved adding (one or more) '=' 

  • vincenzos1984_1 Profile Picture vincenzos1984_1 117
    Posted at
    Parse a bearer token using Flow

    i have used your flow and i have an error:

    Unable to process template language expressions in action 'decode_bearer' inputs at line '1' and column '3440': 'The template language function 'decodeBase64' was invoked with a parameter that is not valid. The value cannot be decoded from base64 representation.'.


    Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlJmS0k2aDJ1aHhwNnJId3V4NzlVY0ZoVnZxdyIsIng1dCI6IlJmS0k2aDJ1aHhwNnJId3V4NzlVY0ZoVnZxdyIsImlzc2xvYyI6IkFNNlBSMDdNQjUxOTIiLCJzcWlkIjo2Mzc1MzUyNjQ4MzQwNjQyNTh9.eyJpYXQiOjE2MTgzNTE2MDEsInZlciI6IlNUSS5FeHRlcm5hbEFjY2Vzc1Rva2VuLlYxIiwiYXBwaWQiOiI0OGFmMDhkYy1mNmQyLTQzNWYtYjJhNy0wNjlhYmQ5OWMwODYiLCJzdWIiOiJhZG1pbkB2c2F2YW5hZGVsYWIub25taWNyb3NvZnQuY29tIiwiYXBwaWRhY3IiOiIyIiwiYWNyIjoiMCIsInRpZCI6IjAwNTUyZGM4LTdjYTEtNDZhYy1hZTI0LTFkN2IzNjViMmRkNyIsInNlbmRlciI6ImFkbWluQHZzYXZhbmFkZWxhYi5vbm1pY3Jvc29mdC5jb20iLCJvaWQiOiIwNmQ0NWZjNS1mMTcyLTQxOGYtYjMwMi1jZDQ3YTJiODAyMjEiLCJpc3MiOiJodHRwczovL3N1YnN0cmF0ZS5vZmZpY2UuY29tL3N0cy8iLCJhdWQiOiJodHRwczovL3Byb2QtNDgud2VzdGV1cm9wZS5sb2dpYy5henVyZS5jb20iLCJleHAiOjE2MTgzNTI1MDEsIm5iZiI6MTYxODM1MTYwMX0.pbR-CcJPjL49QxB8jkKvqDQ9P4OeWm99LQMw5wGExRYahqdThO9NnEfypbyg0-gnYCMJtkxCXh7IuWgYmOBR0ksGk8vFxLOyJfjhYB1iiARMLJ30_JFh3lJo1Q__ZGvNI8UzjM6gNQ3aMWJNTcdCDL0zOLOHV9octEtMQREdGJ1eDFbzi1APSDl1ugasj4q9AP-MJmtIIdUa7MA2BcAy-a6sXIZ8IR0P-x4jfNqT72laMS4pXgIaiSvi2uPuESNYrd_jotZy2zHf35s60fXkjCfI57bbgHZxg6mjAB_EHcBEzPRrWDL5vOmfvFmSZNkoniaroQ9cSwwuC7OCWp-5GA

  • svarukala Profile Picture svarukala Microsoft Employee
    Posted at
    Parse a bearer token using Flow

    @Suga can you share the error that you are seeing? Are you sure that you are not seeing the same error that @liansc reported above in the comments?

  • Suga Profile Picture Suga 6
    Posted at
    Parse a bearer token using Flow

    Hi @svarukala , I was trying to follow your steps, the decode does not work for the token i generated using Oauth2. Can you help me with that

     

    Unfortunately, i will not able to share the token value here. I can PM you if you can help me with fix the decode 

  • svarukala Profile Picture svarukala Microsoft Employee
    Posted at
    Parse a bearer token using Flow

    @liansc looks like an edge case scenario, but good tshooting. 

  • liansc Profile Picture liansc 13
    Posted at
    Parse a bearer token using Flow

    Figured it out - decodeBase64() expects the input's length to be divisible by 4, so as a workaround, I just appended (one or more) '=' characters to my token before decoding. Works ok now.

  • liansc Profile Picture liansc 13
    Posted at
    Parse a bearer token using Flow

    Hi, I incorporated this in one of my flows to extract, decode, and parse a JWT and it works great, however I encounter an error with certain JWT values. After decodeBase64, I get an Unexpected character at the end of the nbf claim, so the ParseJSON action produces an error:

    The 'content' property of actions of type 'ParseJson' must be valid JSON. The provided value cannot be parsed: 'Unexpected character encountered while parsing number: �. Path 'nbf', line 1, position 426.'.

    The output of decodeBase64() is as follows, and it doesn't have a closing brace:

    {"iat":xxx,"ver":"xxx","appid":"xxx","sub":"xxx","appidacr":"x","acr":"x","tid":"xxx","sender":"xxx","oid":"xxx","iss":"xxx","aud":"xxx","exp":1610614832,"nbf":161061393�

    In other cases, it works fine. Any idea what could be wrong? Thanks.