From 78665074edc3a7f3b7bbbe404c5d0f73e308052d Mon Sep 17 00:00:00 2001 From: Eric Chiang <eric.chiang@coreos.com> Date: Mon, 9 Jan 2017 14:50:17 -0800 Subject: [PATCH] cmd/example-app: add option to not request a refresh token --- cmd/example-app/main.go | 5 ++++- cmd/example-app/templates.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/example-app/main.go b/cmd/example-app/main.go index a188dccc..ffa21c29 100644 --- a/cmd/example-app/main.go +++ b/cmd/example-app/main.go @@ -241,12 +241,15 @@ func (a *app) handleLogin(w http.ResponseWriter, r *http.Request) { authCodeURL := "" scopes = append(scopes, "openid", "profile", "email") - if a.offlineAsScope { + if r.FormValue("offline_acecss") != "yes" { + authCodeURL = a.oauth2Config(scopes).AuthCodeURL(exampleAppState) + } else if a.offlineAsScope { scopes = append(scopes, "offline_access") authCodeURL = a.oauth2Config(scopes).AuthCodeURL(exampleAppState) } else { authCodeURL = a.oauth2Config(scopes).AuthCodeURL(exampleAppState, oauth2.AccessTypeOffline) } + http.Redirect(w, r, authCodeURL, http.StatusSeeOther) } diff --git a/cmd/example-app/templates.go b/cmd/example-app/templates.go index 66142540..c0f9dfbd 100644 --- a/cmd/example-app/templates.go +++ b/cmd/example-app/templates.go @@ -14,6 +14,9 @@ var indexTmpl = template.Must(template.New("index.html").Parse(`<html> </p> <p> Extra scopes:<input type="text" name="extra_scopes" placeholder="list of scopes"> + </p> + <p> + Request offline access:<input type="checkbox" name="offline_access" value="yes" checked> </p> <input type="submit" value="Login"> </form> -- GitLab