Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Allow debug printing of raw responses from Authy.
Browse files Browse the repository at this point in the history
To enable, run with environment variable:

    AUTHY_DEBUG=1

This will hopefully make it easier to investigate issues like #1.
  • Loading branch information
alexzorin committed Jul 29, 2019
1 parent 3dfaab9 commit b6a562b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion authy.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package authy

import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -66,7 +68,17 @@ func (c Client) doRequest(ctx context.Context, method, url string, body io.Reade
}
defer resp.Body.Close()

return json.NewDecoder(resp.Body).Decode(&dest)
var r io.Reader = resp.Body
if os.Getenv("AUTHY_DEBUG") == "1" {
var debugBuf bytes.Buffer
r = io.TeeReader(resp.Body, &debugBuf)
defer func() {
fmt.Fprintf(os.Stderr, "[AUTHY_DEBUG] Sent request to: %s, got response: %s\n",
req.URL.String(), debugBuf.String())
}()
}

return json.NewDecoder(r).Decode(&dest)
}

// QueryUser fetches the status of an Authy user account.
Expand Down

0 comments on commit b6a562b

Please sign in to comment.