title: Add Bearer token to Burp-request programatically when "401 Unauthorized" occurs
body: <p>I'm testing a application that uses <code>OAuth2</code> with bearer tokens to authorize requests. The problem I'm having is that the access token expires after 600 seconds (10 minutes) and then all requests become <code>401 Unauthorized</code>. The problem occurring now is that the scanner can continue to run with a bad token and not refresh the token automatically. </p>
  
  <p>What I would like to do in this case is that the application automatically logs back in. </p>
  
  <p>What I have tried is to go to <code>Project options</code> -> <code>Session handling rules</code> -> <code>Add</code> -> <code>Rule Actions</code> -> <code>Check session is valid</code> with options <code>Issue current request</code>. While there I check the response body for "Authorization denied" which is always sent on a HTTP 401. After this happens I have a macro that issues a request to get me a new access token. However I need to map the new access token to the <code>Authorization: Bearer</code>-header. Has anyone done this? It can be easily done with cookies from this view but I can't find how to do it with tokens.</p>
  
  <p>Using <code>Burp Suite Professional v1.7.14</code></p>