Skip to content

Commit

Permalink
Merge pull request dexidp#1395 from hainesc/master
Browse files Browse the repository at this point in the history
Display access token in example app
  • Loading branch information
srenatus authored Feb 4, 2019
2 parents c11d8b2 + d3fa47c commit a0571e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion cmd/example-app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,18 @@ func (a *app) handleCallback(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("Failed to verify ID token: %v", err), http.StatusInternalServerError)
return
}

accessToken, ok := token.Extra("access_token").(string)
if !ok {
http.Error(w, "no access_token in token response", http.StatusInternalServerError)
return
}

var claims json.RawMessage
idToken.Claims(&claims)

buff := new(bytes.Buffer)
json.Indent(buff, []byte(claims), "", " ")

renderToken(w, a.redirectURI, rawIDToken, token.RefreshToken, buff.Bytes())
renderToken(w, a.redirectURI, rawIDToken, accessToken, token.RefreshToken, buff.Bytes())
}
7 changes: 5 additions & 2 deletions cmd/example-app/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func renderIndex(w http.ResponseWriter) {

type tokenTmplData struct {
IDToken string
AccessToken string
RefreshToken string
RedirectURL string
Claims string
Expand All @@ -48,7 +49,8 @@ pre {
</style>
</head>
<body>
<p> Token: <pre><code>{{ .IDToken }}</code></pre></p>
<p> ID Token: <pre><code>{{ .IDToken }}</code></pre></p>
<p> Access Token: <pre><code>{{ .AccessToken }}</code></pre></p>
<p> Claims: <pre><code>{{ .Claims }}</code></pre></p>
{{ if .RefreshToken }}
<p> Refresh Token: <pre><code>{{ .RefreshToken }}</code></pre></p>
Expand All @@ -61,9 +63,10 @@ pre {
</html>
`))

func renderToken(w http.ResponseWriter, redirectURL, idToken, refreshToken string, claims []byte) {
func renderToken(w http.ResponseWriter, redirectURL, idToken, accessToken, refreshToken string, claims []byte) {
renderTemplate(w, tokenTmpl, tokenTmplData{
IDToken: idToken,
AccessToken: accessToken,
RefreshToken: refreshToken,
RedirectURL: redirectURL,
Claims: string(claims),
Expand Down

0 comments on commit a0571e0

Please sign in to comment.