Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
d86a774a
Commit
d86a774a
authored
Nov 04, 2016
by
Eric Chiang
Committed by
GitHub
Nov 04, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #670 from ericchiang/example-app-debug
cmd/example-app: add a --debug flag
parents
ce703a7f
35d6423a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
main.go
cmd/example-app/main.go
+39
-0
No files found.
cmd/example-app/main.go
View file @
d86a774a
...
...
@@ -11,6 +11,7 @@ import (
"log"
"net"
"net/http"
"net/http/httputil"
"net/url"
"os"
"strings"
...
...
@@ -62,6 +63,31 @@ func httpClientForRootCAs(rootCAs string) (*http.Client, error) {
},
nil
}
type
debugTransport
struct
{
t
http
.
RoundTripper
}
func
(
d
debugTransport
)
RoundTrip
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
reqDump
,
err
:=
httputil
.
DumpRequest
(
req
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
log
.
Printf
(
"%s"
,
reqDump
)
resp
,
err
:=
d
.
t
.
RoundTrip
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
respDump
,
err
:=
httputil
.
DumpResponse
(
resp
,
true
)
if
err
!=
nil
{
resp
.
Body
.
Close
()
return
nil
,
err
}
log
.
Printf
(
"%s"
,
respDump
)
return
resp
,
nil
}
func
cmd
()
*
cobra
.
Command
{
var
(
a
app
...
...
@@ -70,6 +96,7 @@ func cmd() *cobra.Command {
tlsCert
string
tlsKey
string
rootCAs
string
debug
bool
)
c
:=
cobra
.
Command
{
Use
:
"example-app"
,
...
...
@@ -101,6 +128,17 @@ func cmd() *cobra.Command {
a
.
ctx
=
context
.
WithValue
(
a
.
ctx
,
oauth2
.
HTTPClient
,
client
)
}
if
debug
{
client
,
ok
:=
a
.
ctx
.
Value
(
oauth2
.
HTTPClient
)
.
(
*
http
.
Client
)
if
ok
{
client
.
Transport
=
debugTransport
{
client
.
Transport
}
}
else
{
a
.
ctx
=
context
.
WithValue
(
a
.
ctx
,
oauth2
.
HTTPClient
,
&
http
.
Client
{
Transport
:
debugTransport
{
http
.
DefaultTransport
},
})
}
}
// TODO(ericchiang): Retry with backoff
provider
,
err
:=
oidc
.
NewProvider
(
a
.
ctx
,
issuerURL
)
if
err
!=
nil
{
...
...
@@ -161,6 +199,7 @@ func cmd() *cobra.Command {
c
.
Flags
()
.
StringVar
(
&
tlsCert
,
"tls-cert"
,
""
,
"X509 cert file to present when serving HTTPS."
)
c
.
Flags
()
.
StringVar
(
&
tlsKey
,
"tls-key"
,
""
,
"Private key for the HTTPS cert."
)
c
.
Flags
()
.
StringVar
(
&
rootCAs
,
"issuer-root-ca"
,
""
,
"Root certificate authorities for the issuer. Defaults to host certs."
)
c
.
Flags
()
.
BoolVar
(
&
debug
,
"debug"
,
false
,
"Print all request and responses from the OpenID Connect issuer."
)
return
&
c
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment