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
9 changes: 5 additions & 4 deletions internal/cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,11 @@ func newAuthManageCmd() *cobra.Command {
var timeout time.Duration

cmd := &cobra.Command{
Use: "manage",
Short: "Open accounts manager in browser",
Long: "Opens a browser-based UI to manage Google accounts, add new accounts, set defaults, and remove accounts.",
Args: cobra.NoArgs,
Use: "manage",
Aliases: []string{"login"},
Short: "Open accounts manager in browser",
Long: "Opens a browser-based UI to manage Google accounts, add new accounts, set defaults, and remove accounts.\n\nAlias: 'gog auth login' is equivalent to 'gog auth manage'.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
var services []googleauth.Service
if strings.EqualFold(strings.TrimSpace(servicesCSV), "") || strings.EqualFold(strings.TrimSpace(servicesCSV), "all") {
Expand Down
18 changes: 8 additions & 10 deletions internal/googleauth/accounts_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (ms *ManageServer) handleOAuthCallback(w http.ResponseWriter, r *http.Reque

// Render success page with the new template
w.WriteHeader(http.StatusOK)
renderSuccessPageNew(w, email, serviceNames)
renderSuccessPageWithDetails(w, email, serviceNames)
}

func (ms *ManageServer) handleSetDefault(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -381,19 +381,17 @@ func writeJSONError(w http.ResponseWriter, msg string, status int) {
_ = json.NewEncoder(w).Encode(map[string]any{"error": msg})
}

// renderSuccessPageNew renders the new success template with email and services
func renderSuccessPageNew(w http.ResponseWriter, email string, services []string) {
tmpl, err := template.New("success").Parse(successTemplateNew)
// renderSuccessPageWithDetails renders the success template with email and services
func renderSuccessPageWithDetails(w http.ResponseWriter, email string, services []string) {
tmpl, err := template.New("success").Parse(successTemplate)
if err != nil {
_, _ = w.Write([]byte("Success! You can close this window."))
return
}
data := struct {
Email string
Services []string
}{
Email: email,
Services: services,
data := successTemplateData{
Email: email,
Services: services,
CountdownSeconds: postSuccessDisplaySeconds,
}
_ = tmpl.Execute(w, data)
}
32 changes: 30 additions & 2 deletions internal/googleauth/oauth_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ type AuthorizeOptions struct {
Timeout time.Duration
}

// postSuccessDisplaySeconds is the number of seconds the success page remains
// visible before the local OAuth server shuts down.
const postSuccessDisplaySeconds = 30

// successTemplateData holds data passed to the success page template.
type successTemplateData struct {
Email string
Services []string
CountdownSeconds int
}

var (
readClientCredentials = config.ReadClientCredentials
openBrowserFn = openBrowser
Expand Down Expand Up @@ -184,14 +195,18 @@ func Authorize(ctx context.Context, opts AuthorizeOptions) (string, error) {

select {
case code := <-codeCh:
_ = srv.Close()
tok, exchangeErr := cfg.Exchange(ctx, code)
if exchangeErr != nil {
_ = srv.Close()
return "", exchangeErr
}
if tok.RefreshToken == "" {
_ = srv.Close()
return "", errors.New("no refresh token received; try again with --force-consent")
}
// Keep server running to show success screen; allow cancellation via Ctrl+C
waitPostSuccess(ctx, postSuccessDisplaySeconds*time.Second)
_ = srv.Close()
return tok.RefreshToken, nil
case err := <-errCh:
_ = srv.Close()
Expand Down Expand Up @@ -241,7 +256,10 @@ func renderSuccessPage(w http.ResponseWriter) {
_, _ = w.Write([]byte("Success! You can close this window."))
return
}
_ = tmpl.Execute(w, nil)
data := successTemplateData{
CountdownSeconds: postSuccessDisplaySeconds,
}
_ = tmpl.Execute(w, data)
}

// renderErrorPage renders the error HTML template with the given message
Expand All @@ -263,3 +281,13 @@ func renderCancelledPage(w http.ResponseWriter) {
}
_ = tmpl.Execute(w, nil)
}

// waitPostSuccess waits for the specified duration or until the context is
// cancelled (e.g., via Ctrl+C). This allows the success page to remain visible
// while still supporting graceful early termination.
func waitPostSuccess(ctx context.Context, d time.Duration) {
select {
case <-time.After(d):
case <-ctx.Done():
}
}
56 changes: 55 additions & 1 deletion internal/googleauth/templates/accounts.html
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='%2334A853' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11.318 12.545H7.91v-1.909h3.41v1.91zM14.728 0v6h6l-6-6zm1.363 10.636h-3.41v1.91h3.41v-1.91zm0 3.273h-3.41v1.91h3.41v-1.91zM20.727 6.5v15.864c0 .904-.732 1.636-1.636 1.636H4.909a1.636 1.636 0 0 1-1.636-1.636V1.636C3.273.732 4.005 0 4.909 0h9.318v6.5h6.5zm-3.273 2.773H6.545v7.909h10.91v-7.91zm-6.136 4.636H7.91v1.91h3.41v-1.91z'/%3E%3C/svg%3E");
}

.service-tag.people {
color: var(--g-blue);
background-color: var(--g-blue-dim);
border-color: rgba(66, 133, 244, 0.2);
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='%234285F4' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E");
}

.service-tag.tasks {
color: var(--g-blue);
background-color: var(--g-blue-dim);
border-color: rgba(66, 133, 244, 0.2);
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='%234285F4' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M22 5.18L10.59 16.6l-4.24-4.24 1.41-1.41 2.83 2.83 10-10L22 5.18zm-2.21 5.04c.13.57.21 1.17.21 1.78 0 4.42-3.58 8-8 8s-8-3.58-8-8 3.58-8 8-8c1.58 0 3.04.46 4.28 1.25l1.44-1.44A9.9 9.9 0 0012 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10c0-1.19-.22-2.33-.6-3.39l-1.61 1.61z'/%3E%3C/svg%3E");
}

.account-actions {
display: flex;
align-items: center;
Expand Down Expand Up @@ -547,6 +561,40 @@
opacity: 0.8;
}

.github-link {
margin-top: 12px;
}

.github-link a {
display: inline-flex;
align-items: center;
color: var(--text-muted);
text-decoration: none;
font-size: 12px;
transition: color 0.2s;
}

.github-link a:hover {
color: var(--g-blue);
}

/* GitHub icon - defined as CSS mask for reuse across templates
* SYNC: If modifying the icon, also update success.html */
.icon-github {
display: inline-block;
width: 14px;
height: 14px;
vertical-align: middle;
margin-right: 4px;
background-color: currentColor;
-webkit-mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z'/%3E%3C/svg%3E");
mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z'/%3E%3C/svg%3E");
-webkit-mask-size: contain;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
}

/* Loading state */
.spinner {
width: 16px;
Expand Down Expand Up @@ -591,7 +639,7 @@
<h1>Google Accounts</h1>
<p class="subtitle">Manage your connected accounts</p>
<p class="setup-link">
<a href="https://github.com/salmonumbrella/gog-cli?tab=readme-ov-file#setup-oauth" target="_blank">
<a href="https://github.com/steipete/gogcli#quick-start" target="_blank">
First time? Set up Google Cloud credentials →
</a>
</p>
Expand Down Expand Up @@ -650,6 +698,12 @@ <h4>Use from terminal</h4>

<footer class="footer">
<p>You can close this window and return to your terminal.</p>
<p class="github-link">
<a href="https://github.com/steipete/gogcli" target="_blank">
<span class="icon-github"></span>
View on GitHub
</a>
</p>
</footer>
</div>

Expand Down
Loading