Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/ausoceantv/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
AUTHORS
Alan Noble <alan@ausocean.org>
David Sutton <david@ausocean.org>
Trek Hopton <trek@ausocean.org>

LICENSE
Copyright (C) 2024 the Australian Ocean Lab (AusOcean)
Expand Down Expand Up @@ -55,7 +57,7 @@ const (
projectID = "ausoceantv"
oauthClientID = "1005382600755-7st09cc91eqcqveviinitqo091dtcmf0.apps.googleusercontent.com"
oauthMaxAge = 60 * 60 * 24 * 7 // 7 days.
version = "v0.5.7"
version = "v0.5.8"
)

// service defines the properties of our web service.
Expand Down
18 changes: 17 additions & 1 deletion gauth/userauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,24 @@ func (ua *UserAuth) LoginHandler(h backend.Handler) error {
return fmt.Errorf("could not save session %s: %w", sessID, err)
}

// Check for refresh token in the user's main session.
hasRefreshToken := false
mainSession, err := h.LoadSession(ua.SessionID)
if err == nil {
tok := &oauth2.Token{}
if err := mainSession.Get(oauthTokenSessionKey, &tok); err == nil && tok != nil && tok.RefreshToken != "" {
hasRefreshToken = true
}
}

// Build auth URL.
opts := []oauth2.AuthCodeOption{oauth2.AccessTypeOffline}
if !hasRefreshToken {
opts = append(opts, oauth2.SetAuthURLParam("prompt", "consent"))
}

// NB: Offline access is required to obtain a refresh token.
url := ua.cfg.AuthCodeURL(sessID, oauth2.AccessTypeOffline)
url := ua.cfg.AuthCodeURL(sessID, opts...)
return h.Redirect(url, http.StatusFound)
}

Expand Down
Loading