diff options
author | Mike Crute <mike@crute.us> | 2021-11-21 20:55:07 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2021-11-21 20:55:07 -0800 |
commit | a62803f932771516ca05a17167b63d1310ce3611 (patch) | |
tree | 7590821b0c15dec34b92fb83d4642c7f58b1f5e8 | |
parent | 7d643bc36cb3cd2594f97d1043a0647aa667758a (diff) | |
download | cloud-identity-broker-a62803f932771516ca05a17167b63d1310ce3611.tar.bz2 cloud-identity-broker-a62803f932771516ca05a17167b63d1310ce3611.tar.xz cloud-identity-broker-a62803f932771516ca05a17167b63d1310ce3611.zip |
Extract URL router interface
-rw-r--r-- | app/middleware/auth.go | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/app/middleware/auth.go b/app/middleware/auth.go index a88313c..58b10a7 100644 --- a/app/middleware/auth.go +++ b/app/middleware/auth.go | |||
@@ -11,6 +11,7 @@ import ( | |||
11 | "code.crute.us/mcrute/cloud-identity-broker/auth" | 11 | "code.crute.us/mcrute/cloud-identity-broker/auth" |
12 | "code.crute.us/mcrute/cloud-identity-broker/auth/github" | 12 | "code.crute.us/mcrute/cloud-identity-broker/auth/github" |
13 | 13 | ||
14 | glecho "code.crute.us/mcrute/golib/echo" | ||
14 | "github.com/labstack/echo/v4" | 15 | "github.com/labstack/echo/v4" |
15 | "github.com/prometheus/client_golang/prometheus" | 16 | "github.com/prometheus/client_golang/prometheus" |
16 | "github.com/prometheus/client_golang/prometheus/promauto" | 17 | "github.com/prometheus/client_golang/prometheus/promauto" |
@@ -25,13 +26,6 @@ var apiKeyRequests = promauto.NewCounterVec(prometheus.CounterOpts{ | |||
25 | Help: "Total number of requests using the X-API-Key header", | 26 | Help: "Total number of requests using the X-API-Key header", |
26 | }, nil) | 27 | }, nil) |
27 | 28 | ||
28 | // canRegisterUrls is an interface that identifies what about an HTTP router is | ||
29 | // needed by this middleware. This mainly exists to work around the fact that | ||
30 | // our server is actually a golib.EchoWrapper and not an echo.Echo. | ||
31 | type canRegisterUrls interface { | ||
32 | GET(string, echo.HandlerFunc, ...echo.MiddlewareFunc) *echo.Route | ||
33 | } | ||
34 | |||
35 | const ( | 29 | const ( |
36 | authPrincipalContextKey = "broker.AuthorizedPrincipal" | 30 | authPrincipalContextKey = "broker.AuthorizedPrincipal" |
37 | gitHubTokenCookie = "github-token" | 31 | gitHubTokenCookie = "github-token" |
@@ -85,7 +79,7 @@ func (m *AuthenticationMiddleware) redirectToGitHubAuth(c echo.Context) error { | |||
85 | // This is here instead of in the web main because these paths are encoded in | 79 | // This is here instead of in the web main because these paths are encoded in |
86 | // the configuration for the GitHub application so changing them requires | 80 | // the configuration for the GitHub application so changing them requires |
87 | // addition changes to that configuration. | 81 | // addition changes to that configuration. |
88 | func (m *AuthenticationMiddleware) RegisterUrls(e canRegisterUrls) { | 82 | func (m *AuthenticationMiddleware) RegisterUrls(e glecho.URLRouter) { |
89 | e.GET(oauthReturnUrl, m.HandleCompleteLogin) | 83 | e.GET(oauthReturnUrl, m.HandleCompleteLogin) |
90 | } | 84 | } |
91 | 85 | ||