code: def build_xoauth_string(url, consumer, token=None):
      
      request = Request.from_consumer_and_token(consumer, token,
          "GET", url)
  
      signing_method = SignatureMethod_HMAC_SHA1()
      request.sign_request(signing_method, consumer, token)
  
      params = []
      for k, v in sorted(request.items()):
          if v is not None:
              params.append('%s="%s"' % (k, escape(v)))
  
      return "%s %s %s" % ("GET", url, ','.join(params))
docs: Build an XOAUTH string for use in SMTP/IMPA authentication.