OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package openid | 5 package openid |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "net/http" | 9 "net/http" |
10 "net/url" | 10 "net/url" |
11 "path" | 11 "path" |
12 "strings" | 12 "strings" |
13 "time" | 13 "time" |
14 | 14 |
15 "golang.org/x/net/context" | 15 "golang.org/x/net/context" |
16 | 16 |
17 "github.com/luci/luci-go/common/clock" | 17 "github.com/luci/luci-go/common/clock" |
18 "github.com/luci/luci-go/common/errors" | 18 "github.com/luci/luci-go/common/errors" |
19 "github.com/luci/luci-go/common/logging" | 19 "github.com/luci/luci-go/common/logging" |
| 20 "github.com/luci/luci-go/common/retry/transient" |
20 "github.com/luci/luci-go/server/auth" | 21 "github.com/luci/luci-go/server/auth" |
21 "github.com/luci/luci-go/server/router" | 22 "github.com/luci/luci-go/server/router" |
22 ) | 23 ) |
23 | 24 |
24 // These are installed into a HTTP router by AuthMethod.InstallHandlers(...). | 25 // These are installed into a HTTP router by AuthMethod.InstallHandlers(...). |
25 const ( | 26 const ( |
26 loginURL = "/auth/openid/login" | 27 loginURL = "/auth/openid/login" |
27 logoutURL = "/auth/openid/logout" | 28 logoutURL = "/auth/openid/logout" |
28 callbackURL = "/auth/openid/callback" | 29 callbackURL = "/auth/openid/callback" |
29 ) | 30 ) |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 cpy.MaxAge = -1 | 358 cpy.MaxAge = -1 |
358 cpy.Expires = time.Unix(1, 0) | 359 cpy.Expires = time.Unix(1, 0) |
359 http.SetCookie(rw, &cpy) | 360 http.SetCookie(rw, &cpy) |
360 } | 361 } |
361 } | 362 } |
362 | 363 |
363 // replyError logs the error and replies with HTTP 500 (on transient errors) or | 364 // replyError logs the error and replies with HTTP 500 (on transient errors) or |
364 // HTTP 400 on fatal errors (that can happen only on bad requests). | 365 // HTTP 400 on fatal errors (that can happen only on bad requests). |
365 func replyError(c context.Context, rw http.ResponseWriter, err error, msg string
, args ...interface{}) { | 366 func replyError(c context.Context, rw http.ResponseWriter, err error, msg string
, args ...interface{}) { |
366 code := http.StatusBadRequest | 367 code := http.StatusBadRequest |
367 » if errors.IsTransient(err) { | 368 » if transient.Tag.In(err) { |
368 code = http.StatusInternalServerError | 369 code = http.StatusInternalServerError |
369 } | 370 } |
370 msg = fmt.Sprintf(msg, args...) | 371 msg = fmt.Sprintf(msg, args...) |
371 logging.Errorf(c, "HTTP %d: %s", code, msg) | 372 logging.Errorf(c, "HTTP %d: %s", code, msg) |
372 http.Error(rw, msg, code) | 373 http.Error(rw, msg, code) |
373 } | 374 } |
OLD | NEW |