| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package server | 5 package server |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "runtime" |
| 9 "strings" |
| 10 |
| 8 "github.com/julienschmidt/httprouter" | 11 "github.com/julienschmidt/httprouter" |
| 9 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
| 10 "google.golang.org/appengine" | 13 "google.golang.org/appengine" |
| 11 | 14 |
| 12 "github.com/luci/luci-go/server/auth" | 15 "github.com/luci/luci-go/server/auth" |
| 13 "github.com/luci/luci-go/server/auth/admin" | 16 "github.com/luci/luci-go/server/auth/admin" |
| 17 "github.com/luci/luci-go/server/auth/info" |
| 14 "github.com/luci/luci-go/server/auth/openid" | 18 "github.com/luci/luci-go/server/auth/openid" |
| 15 "github.com/luci/luci-go/server/auth/signing" | 19 "github.com/luci/luci-go/server/auth/signing" |
| 16 "github.com/luci/luci-go/server/middleware" | 20 "github.com/luci/luci-go/server/middleware" |
| 17 | 21 |
| 18 "github.com/luci/luci-go/appengine/gaeauth/server/internal/authdb" | 22 "github.com/luci/luci-go/appengine/gaeauth/server/internal/authdb" |
| 19 ) | 23 ) |
| 20 | 24 |
| 21 // CookieAuth is default cookie-based auth method to use on GAE. | 25 // CookieAuth is default cookie-based auth method to use on GAE. |
| 22 // | 26 // |
| 23 // On dev server it is based on dev server cookies, in prod it is based on | 27 // On dev server it is based on dev server cookies, in prod it is based on |
| 24 // OpenID. Works only if appropriate handlers have been installed into | 28 // OpenID. Works only if appropriate handlers have been installed into |
| 25 // the router. See InstallHandlers. | 29 // the router. See InstallHandlers. |
| 26 var CookieAuth auth.Method | 30 var CookieAuth auth.Method |
| 27 | 31 |
| 28 // InstallHandlers installs HTTP handlers for various routes related | 32 // InstallHandlers installs HTTP handlers for various routes related |
| 29 // to authentication system. | 33 // to authentication system. |
| 30 // | 34 // |
| 31 // Must be installed in server HTTP router for authentication to work. | 35 // Must be installed in server HTTP router for authentication to work. |
| 32 func InstallHandlers(r *httprouter.Router, base middleware.Base) { | 36 func InstallHandlers(r *httprouter.Router, base middleware.Base) { |
| 33 m := CookieAuth.(cookieAuthMethod) | 37 m := CookieAuth.(cookieAuthMethod) |
| 34 if oid, ok := m.Method.(*openid.AuthMethod); ok { | 38 if oid, ok := m.Method.(*openid.AuthMethod); ok { |
| 35 oid.InstallHandlers(r, base) | 39 oid.InstallHandlers(r, base) |
| 36 } | 40 } |
| 37 admin.InstallHandlers(r, base, &UsersAPIAuthMethod{}, adminPagesConfig{}
) | 41 admin.InstallHandlers(r, base, &UsersAPIAuthMethod{}, adminPagesConfig{}
) |
| 38 auth.InstallHandlers(r, base) | 42 auth.InstallHandlers(r, base) |
| 39 authdb.InstallHandlers(r, base) | 43 authdb.InstallHandlers(r, base) |
| 44 info.InstallHandlers(r, base, getServiceInfo) |
| 40 signing.InstallHandlers(r, base) | 45 signing.InstallHandlers(r, base) |
| 41 } | 46 } |
| 42 | 47 |
| 43 // Warmup prepares local caches. It's optional. | 48 // Warmup prepares local caches. It's optional. |
| 44 func Warmup(c context.Context) error { | 49 func Warmup(c context.Context) error { |
| 45 m := CookieAuth.(cookieAuthMethod) | 50 m := CookieAuth.(cookieAuthMethod) |
| 46 if oid, ok := m.Method.(*openid.AuthMethod); ok { | 51 if oid, ok := m.Method.(*openid.AuthMethod); ok { |
| 47 return oid.Warmup(c) | 52 return oid.Warmup(c) |
| 48 } | 53 } |
| 49 return nil | 54 return nil |
| 50 } | 55 } |
| 51 | 56 |
| 57 func getServiceInfo(c context.Context) (info.ServiceInfo, error) { |
| 58 account, err := appengine.ServiceAccount(c) |
| 59 if err != nil { |
| 60 return info.ServiceInfo{}, err |
| 61 } |
| 62 return info.ServiceInfo{ |
| 63 AppID: appengine.AppID(c), |
| 64 AppRuntime: "go", |
| 65 AppRuntimeVersion: runtime.Version(), |
| 66 AppVersion: strings.Split(appengine.VersionID(c), ".")[0
], |
| 67 ServiceAccountName: account, |
| 68 }, nil |
| 69 } |
| 70 |
| 52 /// | 71 /// |
| 53 | 72 |
| 54 // adminPagesConfig is used by server/auth/admin to display admin UI | 73 // adminPagesConfig is used by server/auth/admin to display admin UI |
| 55 type adminPagesConfig struct{} | 74 type adminPagesConfig struct{} |
| 56 | 75 |
| 57 func (adminPagesConfig) GetAppServiceAccount(c context.Context) (string, error)
{ | 76 func (adminPagesConfig) GetAppServiceAccount(c context.Context) (string, error)
{ |
| 58 return appengine.ServiceAccount(c) | 77 return appengine.ServiceAccount(c) |
| 59 } | 78 } |
| 60 | 79 |
| 61 func (adminPagesConfig) GetReplicationState(c context.Context) (string, int64, e
rror) { | 80 func (adminPagesConfig) GetReplicationState(c context.Context) (string, int64, e
rror) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 91 CookieAuth = cookieAuthMethod{UsersAPIAuthMethod{}} | 110 CookieAuth = cookieAuthMethod{UsersAPIAuthMethod{}} |
| 92 } else { | 111 } else { |
| 93 CookieAuth = cookieAuthMethod{ | 112 CookieAuth = cookieAuthMethod{ |
| 94 &openid.AuthMethod{ | 113 &openid.AuthMethod{ |
| 95 SessionStore: &SessionStore{Namespace: "o
penid"}, | 114 SessionStore: &SessionStore{Namespace: "o
penid"}, |
| 96 IncompatibleCookies: []string{"SACSID", "dev_app
server_login"}, | 115 IncompatibleCookies: []string{"SACSID", "dev_app
server_login"}, |
| 97 }, | 116 }, |
| 98 } | 117 } |
| 99 } | 118 } |
| 100 } | 119 } |
| OLD | NEW |