Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Side by Side Diff: appengine/gaeauth/server/default.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Update tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 server 5 package server
6 6
7 import ( 7 import (
8 "runtime" 8 "runtime"
9 "strings" 9 "strings"
10 10
11 "github.com/julienschmidt/httprouter"
12 "golang.org/x/net/context" 11 "golang.org/x/net/context"
13 "google.golang.org/appengine" 12 "google.golang.org/appengine"
14 13
15 gae_info "github.com/luci/gae/service/info" 14 gae_info "github.com/luci/gae/service/info"
16 "github.com/luci/luci-go/server/auth" 15 "github.com/luci/luci-go/server/auth"
17 "github.com/luci/luci-go/server/auth/info" 16 "github.com/luci/luci-go/server/auth/info"
18 "github.com/luci/luci-go/server/auth/openid" 17 "github.com/luci/luci-go/server/auth/openid"
19 "github.com/luci/luci-go/server/auth/signing" 18 "github.com/luci/luci-go/server/auth/signing"
20 » "github.com/luci/luci-go/server/middleware" 19 » "github.com/luci/luci-go/server/router"
21 20
22 "github.com/luci/luci-go/appengine/gaeauth/server/internal/authdb" 21 "github.com/luci/luci-go/appengine/gaeauth/server/internal/authdb"
23 ) 22 )
24 23
25 // CookieAuth is default cookie-based auth method to use on GAE. 24 // CookieAuth is default cookie-based auth method to use on GAE.
26 // 25 //
27 // On dev server it is based on dev server cookies, in prod it is based on 26 // On dev server it is based on dev server cookies, in prod it is based on
28 // OpenID. Works only if appropriate handlers have been installed into 27 // OpenID. Works only if appropriate handlers have been installed into
29 // the router. See InstallHandlers. 28 // the router. See InstallHandlers.
30 var CookieAuth auth.Method 29 var CookieAuth auth.Method
31 30
32 // InstallWebHandlers installs HTTP handlers for various default routes related 31 // InstallWebHandlers installs HTTP handlers for various default routes related
33 // to authentication system. 32 // to authentication system.
34 // 33 //
35 // Must be installed in server HTTP router for authentication to work. 34 // Must be installed in server HTTP router for authentication to work.
36 // 35 //
37 // TODO(vadimsh): Rename to InstallHandlers after June 1 2016. It was renamed 36 // TODO(vadimsh): Rename to InstallHandlers after June 1 2016. It was renamed
38 // to purposely break code that called it (since its semantics has changed). 37 // to purposely break code that called it (since its semantics has changed).
39 func InstallWebHandlers(r *httprouter.Router, base middleware.Base) { 38 func InstallWebHandlers(r *router.Router, handlers []router.Handler) {
40 m := CookieAuth.(cookieAuthMethod) 39 m := CookieAuth.(cookieAuthMethod)
41 if oid, ok := m.Method.(*openid.AuthMethod); ok { 40 if oid, ok := m.Method.(*openid.AuthMethod); ok {
42 » » oid.InstallHandlers(r, base) 41 » » oid.InstallHandlers(r, handlers)
43 } 42 }
44 » auth.InstallHandlers(r, base) 43 » auth.InstallHandlers(r, handlers)
45 » authdb.InstallHandlers(r, base) 44 » authdb.InstallHandlers(r, handlers)
46 » info.InstallHandlers(r, base, getServiceInfo) 45 » info.InstallHandlers(r, handlers, getServiceInfo)
47 » signing.InstallHandlers(r, base) 46 » signing.InstallHandlers(r, handlers)
48 } 47 }
49 48
50 // Warmup prepares local caches. It's optional. 49 // Warmup prepares local caches. It's optional.
51 func Warmup(c context.Context) error { 50 func Warmup(c context.Context) error {
52 m := CookieAuth.(cookieAuthMethod) 51 m := CookieAuth.(cookieAuthMethod)
53 if oid, ok := m.Method.(*openid.AuthMethod); ok { 52 if oid, ok := m.Method.(*openid.AuthMethod); ok {
54 return oid.Warmup(c) 53 return oid.Warmup(c)
55 } 54 }
56 return nil 55 return nil
57 } 56 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 CookieAuth = cookieAuthMethod{UsersAPIAuthMethod{}} 92 CookieAuth = cookieAuthMethod{UsersAPIAuthMethod{}}
94 } else { 93 } else {
95 CookieAuth = cookieAuthMethod{ 94 CookieAuth = cookieAuthMethod{
96 &openid.AuthMethod{ 95 &openid.AuthMethod{
97 SessionStore: &SessionStore{Prefix: "open id"}, 96 SessionStore: &SessionStore{Prefix: "open id"},
98 IncompatibleCookies: []string{"SACSID", "dev_app server_login"}, 97 IncompatibleCookies: []string{"SACSID", "dev_app server_login"},
99 }, 98 },
100 } 99 }
101 } 100 }
102 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698