diff options
author | Tuomo Ala-Vannesluoma <tuomoav@gmail.com> | 2018-09-10 15:55:32 +0300 |
---|---|---|
committer | Tuomo Ala-Vannesluoma <tuomoav@gmail.com> | 2018-09-10 15:55:32 +0300 |
commit | 82028462a4c14b947bd897598aa12f16796ea6c3 (patch) | |
tree | e74ace59a083912272406bcf1035b9d514e9ba7d /internal/auth/auth.go | |
parent | ce5d10b13b433220a9e8a9c1f91b430098382b4e (diff) |
Refactor to use the same store
Diffstat (limited to 'internal/auth/auth.go')
-rw-r--r-- | internal/auth/auth.go | 20 |
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)), } } |