Display access token in example app
This commit is contained in:
parent
f1581ff873
commit
18b6b34b67
@ -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)
|
http.Error(w, fmt.Sprintf("Failed to verify ID token: %v", err), http.StatusInternalServerError)
|
||||||
return
|
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
|
var claims json.RawMessage
|
||||||
idToken.Claims(&claims)
|
idToken.Claims(&claims)
|
||||||
|
|
||||||
buff := new(bytes.Buffer)
|
buff := new(bytes.Buffer)
|
||||||
json.Indent(buff, []byte(claims), "", " ")
|
json.Indent(buff, []byte(claims), "", " ")
|
||||||
|
|
||||||
renderToken(w, a.redirectURI, rawIDToken, token.RefreshToken, buff.Bytes())
|
renderToken(w, a.redirectURI, rawIDToken, accessToken, token.RefreshToken, buff.Bytes())
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ func renderIndex(w http.ResponseWriter) {
|
|||||||
|
|
||||||
type tokenTmplData struct {
|
type tokenTmplData struct {
|
||||||
IDToken string
|
IDToken string
|
||||||
|
AccessToken string
|
||||||
RefreshToken string
|
RefreshToken string
|
||||||
RedirectURL string
|
RedirectURL string
|
||||||
Claims string
|
Claims string
|
||||||
@ -48,7 +49,8 @@ pre {
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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>
|
<p> Claims: <pre><code>{{ .Claims }}</code></pre></p>
|
||||||
{{ if .RefreshToken }}
|
{{ if .RefreshToken }}
|
||||||
<p> Refresh Token: <pre><code>{{ .RefreshToken }}</code></pre></p>
|
<p> Refresh Token: <pre><code>{{ .RefreshToken }}</code></pre></p>
|
||||||
@ -61,9 +63,10 @@ pre {
|
|||||||
</html>
|
</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{
|
renderTemplate(w, tokenTmpl, tokenTmplData{
|
||||||
IDToken: idToken,
|
IDToken: idToken,
|
||||||
|
AccessToken: accessToken,
|
||||||
RefreshToken: refreshToken,
|
RefreshToken: refreshToken,
|
||||||
RedirectURL: redirectURL,
|
RedirectURL: redirectURL,
|
||||||
Claims: string(claims),
|
Claims: string(claims),
|
||||||
|
Reference in New Issue
Block a user