locked
Azure CDN with SAS Token and Authentication Token RRS feed

  • Question

  • I'm having a hard time getting token authentication working on my CDN endpoint and am hoping someone can point me in the right direction.

    I have a verizon premium CDN set up as follows:

    CDN is backed by blob storage which requires a SAS key

    CDN is configured to require token authentication for any requests under /secure (relative to origin)

    What this means (I think):

    1) All requests will need to go through a URL rewrite rule to append the required SAS token 

    2) Some incoming requests will be of the form

    - /path/foo.jpg   (no query string, so I need to append    ?<SAS token> in the rewrite rule)

    - /secure/bar.jpg?authentication_token   (query string exists, so I need to append &<SAS token> in the rewrite rule)


    I've tried the following rule, but it doesn't work:

    IF Always

    URL Rewrite

    Source:  /######/endpoint       ([^\?]+)(\?)?(.+)?

    Destination:  /######/endpoint      $1?<SAS_TOKEN>&$3 

    According to https://www.regexpal.com/ that regular expression should do the trick, matching everything before the ? and everything after it, then allowing me to piece everything back together with $1 and $3  ($2 is just the ?, so it's unused.

    Can anyone help me with this?  Or, barring being able to fix it for me, can anyone point me to somewhere I can debug what's actually going on without trying something and then waiting 90 minutes before seeing that it doesn't work and not knowing why?  Surely there has to be a better way.

    Thanks,

    Mike

    Saturday, April 7, 2018 1:46 AM

Answers

  • Of course as soon as I posted this, I believe it's working. I had to change the ? at the beginning of the querystring to be outside of a capturing group and then change the rewritten URL to only use $1 (before the querystring) and $2 (the querystring)

    For anyone hitting this same issue - here's the regex I used to get this working:

    Source:    ([^\?]+)[\?]?(.+)?

    Destination:  $1?<SAS_TOKEN>&$2

    Saturday, April 7, 2018 3:33 AM