Skip to content

Commit 8bfcfcb

Browse files
akosyakovroboquat
authored andcommitted
[local-app] fix failed/cancelled auth
1 parent 4619722 commit 8bfcfcb

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

components/local-app/main.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,21 @@ func main() {
9393
},
9494
},
9595
&cli.BoolFlag{
96-
Name: "verbose",
96+
Name: "verbose",
97+
Usage: "Enable verbose logging",
9798
EnvVars: []string{
9899
"GITPOD_LCA_VERBOSE",
99100
},
100101
Value: false,
101102
},
103+
&cli.DurationFlag{
104+
Name: "auth-timeout",
105+
Usage: "Auth timeout in seconds",
106+
EnvVars: []string{
107+
"GITPOD_LCA_AUTH_TIMEOUT",
108+
},
109+
Value: 30,
110+
},
102111
},
103112
Commands: []*cli.Command{
104113
{
@@ -107,7 +116,8 @@ func main() {
107116
if c.Bool("mock-keyring") {
108117
keyring.MockInit()
109118
}
110-
return run(c.String("gitpod-host"), c.String("ssh_config"), c.Int("api-port"), c.Bool("allow-cors-from-port"), c.Bool("auto-tunnel"), c.String("auth-redirect-url"), c.Bool("verbose"))
119+
return run(c.String("gitpod-host"), c.String("ssh_config"), c.Int("api-port"), c.Bool("allow-cors-from-port"),
120+
c.Bool("auto-tunnel"), c.String("auth-redirect-url"), c.Bool("verbose"), c.Duration("auth-timeout"))
111121
},
112122
Flags: []cli.Flag{
113123
&cli.PathFlag{
@@ -131,7 +141,7 @@ func DefaultCommand(name string) cli.ActionFunc {
131141
}
132142
}
133143

134-
func run(origin, sshConfig string, apiPort int, allowCORSFromPort bool, autoTunnel bool, authRedirectUrl string, verbose bool) error {
144+
func run(origin, sshConfig string, apiPort int, allowCORSFromPort bool, autoTunnel bool, authRedirectUrl string, verbose bool, authTimeout time.Duration) error {
135145
if verbose {
136146
logrus.SetLevel(logrus.DebugLevel)
137147
}
@@ -155,7 +165,7 @@ func run(origin, sshConfig string, apiPort int, allowCORSFromPort bool, autoTunn
155165

156166
var b *bastion.Bastion
157167

158-
client, err := connectToServer(auth.LoginOpts{GitpodURL: origin, RedirectURL: authRedirectUrl}, func() {
168+
client, err := connectToServer(auth.LoginOpts{GitpodURL: origin, RedirectURL: authRedirectUrl, AuthTimeout: authTimeout}, func() {
159169
if b != nil {
160170
b.FullUpdate()
161171
}

components/local-app/pkg/auth/auth.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"net/http"
1616
"net/url"
1717
"strings"
18+
"time"
1819

1920
jwt "github.com/dgrijalva/jwt-go"
2021
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
@@ -95,6 +96,7 @@ func DeleteToken(host string) error {
9596
type LoginOpts struct {
9697
GitpodURL string
9798
RedirectURL string
99+
AuthTimeout time.Duration
98100
}
99101

100102
const html = `
@@ -201,6 +203,7 @@ func Login(ctx context.Context, opts LoginOpts) (token string, err error) {
201203
return "", xerrors.Errorf("cannot open browser to URL %s: %s\n", authorizationURL, err)
202204
}
203205

206+
authTimeout := time.NewTimer(opts.AuthTimeout * time.Second)
204207
var query url.Values
205208
var code, approved string
206209
select {
@@ -211,6 +214,8 @@ func Login(ctx context.Context, opts LoginOpts) (token string, err error) {
211214
case query = <-queryChan:
212215
code = query.Get("code")
213216
approved = query.Get("approved")
217+
case <-authTimeout.C:
218+
return "", xerrors.Errorf("auth timeout after %d seconds", uint32(opts.AuthTimeout))
214219
}
215220

216221
if approved == "no" {

components/server/src/oauth-server/oauth-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class OAuthController {
5151

5252
// Let the local app know they rejected the approval
5353
const rt = req.query.redirect_uri;
54-
if (!rt || !rt.startsWith("http://localhost:")) {
54+
if (!rt || !rt.startsWith("http://127.0.0.1:")) {
5555
log.error(`/oauth/authorize: invalid returnTo URL: "${rt}"`)
5656
res.sendStatus(400);
5757
return false;

0 commit comments

Comments
 (0)