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

Side by Side Diff: milo/appengine/common/middleware.go

Issue 2830443003: auth: Refactor how authentication methods are passed to server/auth library. (Closed)
Patch Set: Created 3 years, 8 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 common 5 package common
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 "strings" 9 "strings"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 "Analytics": analytics.Snippet(c), 49 "Analytics": analytics.Snippet(c),
50 "RequestID": info.RequestID(c), 50 "RequestID": info.RequestID(c),
51 }, nil 51 }, nil
52 }, 52 },
53 FuncMap: funcMap, 53 FuncMap: funcMap,
54 } 54 }
55 } 55 }
56 56
57 // Base returns the basic LUCI appengine middlewares. 57 // Base returns the basic LUCI appengine middlewares.
58 func Base() router.MiddlewareChain { 58 func Base() router.MiddlewareChain {
59 » methods := auth.Authenticator{ 59 » m := gaemiddleware.BaseProd().Extend(auth.Authenticate(&auth.Authenticat or{
60 » » &server.OAuth2Method{Scopes: []string{server.EmailScope}}, 60 » » Methods: []auth.Method{
61 » » server.CookieAuth, 61 » » » &server.OAuth2Method{Scopes: []string{server.EmailScope} },
62 » » &server.InboundAppIDAuthMethod{}, 62 » » » server.CookieAuth,
63 » } 63 » » » &server.InboundAppIDAuthMethod{},
64 » m := gaemiddleware.BaseProd().Extend(auth.Use(methods), auth.Authenticat e) 64 » » },
65 » }))
65 m = m.Extend(withRequestMiddleware) 66 m = m.Extend(withRequestMiddleware)
66 m = m.Extend(templates.WithTemplates(GetTemplateBundle())) 67 m = m.Extend(templates.WithTemplates(GetTemplateBundle()))
67 return m 68 return m
68 } 69 }
69 70
70 // The context key, so that we can embed the http.Request object into 71 // The context key, so that we can embed the http.Request object into
71 // the context. 72 // the context.
72 var requestKey = "http.request" 73 var requestKey = "http.request"
73 74
74 // WithRequest returns a context with the http.Request object 75 // WithRequest returns a context with the http.Request object
75 // in it. 76 // in it.
76 func WithRequest(c context.Context, r *http.Request) context.Context { 77 func WithRequest(c context.Context, r *http.Request) context.Context {
77 return context.WithValue(c, &requestKey, r) 78 return context.WithValue(c, &requestKey, r)
78 } 79 }
79 80
80 // withRequestMiddleware is a middleware that installs a request into the contex t. 81 // withRequestMiddleware is a middleware that installs a request into the contex t.
81 // This is used for various things in the default template. 82 // This is used for various things in the default template.
82 func withRequestMiddleware(c *router.Context, next router.Handler) { 83 func withRequestMiddleware(c *router.Context, next router.Handler) {
83 c.Context = WithRequest(c.Context, c.Request) 84 c.Context = WithRequest(c.Context, c.Request)
84 next(c) 85 next(c)
85 } 86 }
86 87
87 func getRequest(c context.Context) *http.Request { 88 func getRequest(c context.Context) *http.Request {
88 if req, ok := c.Value(&requestKey).(*http.Request); ok { 89 if req, ok := c.Value(&requestKey).(*http.Request); ok {
89 return req 90 return req
90 } 91 }
91 panic("No http.request found in context") 92 panic("No http.request found in context")
92 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698