diff --git a/cmd/example-app/main.go b/cmd/example-app/main.go index d88b6838..21b025d2 100644 --- a/cmd/example-app/main.go +++ b/cmd/example-app/main.go @@ -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()) } diff --git a/cmd/example-app/templates.go b/cmd/example-app/templates.go index a870d0f0..3a4b5bb2 100644 --- a/cmd/example-app/templates.go +++ b/cmd/example-app/templates.go @@ -29,6 +29,7 @@ func renderIndex(w http.ResponseWriter) { type tokenTmplData struct { IDToken string + AccessToken string RefreshToken string RedirectURL string Claims string @@ -48,7 +49,8 @@ pre {
-Token:
{{ .IDToken }}
+ ID Token:
{{ .IDToken }}
+ Access Token:
{{ .AccessToken }}
Claims:
{{ .Claims }}
{{ if .RefreshToken }}
Refresh Token:
{{ .RefreshToken }}
@@ -61,9 +63,10 @@ pre {
`))
-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),