Skip to content

Commit

Permalink
oauth2/recovation: resolve issues with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeneas Rekkas (arekkas) authored and arekkas committed Nov 22, 2016
1 parent 994b596 commit 2e58355
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cmd/cli/handler_recovation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/ory-am/hydra/pkg"
"github.com/spf13/cobra"
"golang.org/x/oauth2/clientcredentials"
"crypto/tls"
"net/http"
)

type RevocationHandler struct {
Expand All @@ -23,6 +25,13 @@ func newRevocationHandler(c *config.Config) *RevocationHandler {
}

func (h *RevocationHandler) RevokeToken(cmd *cobra.Command, args []string) {
if ok, _ := cmd.Flags().GetBool("skip-tls-verify"); ok {
fmt.Println("Warning: Skipping TLS Certificate Verification.")
h.M.Client = &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}}
}

h.M.Endpoint = h.Config.Resolve("/oauth2/revoke")
h.M.Config = &clientcredentials.Config{
ClientID: h.Config.ClientID,
Expand Down
6 changes: 5 additions & 1 deletion oauth2/revocator_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type HTTPRecovator struct {
Config *clientcredentials.Config
Dry bool
Endpoint *url.URL
Client *http.Client
}

func (r *HTTPRecovator) RevokeToken(ctx context.Context, token string) error {
Expand All @@ -30,7 +31,10 @@ func (r *HTTPRecovator) RevokeToken(ctx context.Context, token string) error {
hreq.Header.Add("Content-Type", "application/x-www-form-urlencoded")
hreq.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
hreq.SetBasicAuth(r.Config.ClientID, r.Config.ClientSecret)
hres, err := http.DefaultClient.Do(hreq)
if r.Client == nil {
r.Client = http.DefaultClient
}
hres, err := r.Client.Do(hreq)
if err != nil {
return errors.Wrap(err, "")
}
Expand Down

0 comments on commit 2e58355

Please sign in to comment.