Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuomo Ala-Vannesluoma <tuomoav@gmail.com>2018-09-10 15:55:32 +0300
committerTuomo Ala-Vannesluoma <tuomoav@gmail.com>2018-09-10 15:55:32 +0300
commit82028462a4c14b947bd897598aa12f16796ea6c3 (patch)
treee74ace59a083912272406bcf1035b9d514e9ba7d
parentce5d10b13b433220a9e8a9c1f91b430098382b4e (diff)
Refactor to use the same store
-rw-r--r--internal/auth/auth.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/internal/auth/auth.go b/internal/auth/auth.go
index f1fe03c0..ab661d3d 100644
--- a/internal/auth/auth.go
+++ b/internal/auth/auth.go
@@ -37,8 +37,8 @@ type Auth struct {
clientSecret string
redirectURI string
gitLabServer string
- storeSecret string
apiClient *http.Client
+ store sessions.Store
}
type tokenResponse struct {
@@ -54,20 +54,22 @@ type errorResponse struct {
}
func (a *Auth) getSessionFromStore(r *http.Request) (*sessions.Session, error) {
- store := sessions.NewCookieStore([]byte(a.storeSecret))
-
host, _, err := net.SplitHostPort(r.Host)
if err != nil {
host = r.Host
}
- // Cookie just for this domain
- store.Options = &sessions.Options{
- Path: "/",
- Domain: host,
+ session, err := a.store.Get(r, "gitlab-pages")
+
+ if session != nil {
+ // Cookie just for this domain
+ session.Options = &sessions.Options{
+ Path: "/",
+ Domain: host,
+ }
}
- return store.Get(r, "gitlab-pages")
+ return session, err
}
func (a *Auth) checkSession(w http.ResponseWriter, r *http.Request) (*sessions.Session, error) {
@@ -502,10 +504,10 @@ func New(pagesDomain string, storeSecret string, clientID string, clientSecret s
clientSecret: clientSecret,
redirectURI: redirectURI,
gitLabServer: strings.TrimRight(gitLabServer, "/"),
- storeSecret: storeSecret,
apiClient: &http.Client{
Timeout: 5 * time.Second,
Transport: httptransport.Transport,
},
+ store: sessions.NewCookieStore([]byte(storeSecret)),
}
}