Skip to content
Snippets Groups Projects
Commit 54e3f0f7 authored by Niall Sheridan's avatar Niall Sheridan
Browse files

Set expiry time in the github auth package

parent 69973a0c
Branches
Tags
No related merge requests found
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"net/http" "net/http"
"os" "os"
"strings" "strings"
"time"
"golang.org/x/oauth2" "golang.org/x/oauth2"
...@@ -133,11 +132,6 @@ func callbackHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int ...@@ -133,11 +132,6 @@ func callbackHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int
if err := a.authsession.Authorize(a.authprovider, code); err != nil { if err := a.authsession.Authorize(a.authprovider, code); err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }
// Github tokens don't have an expiry. Set one so that the session expires
// after a period.
if a.authsession.Token.Expiry.Unix() <= 0 {
a.authsession.Token.Expiry = time.Now().Add(1 * time.Hour)
}
a.setAuthCookie(w, r, a.authsession.Token) a.setAuthCookie(w, r, a.authsession.Token)
http.Redirect(w, r, "/", http.StatusFound) http.Redirect(w, r, "/", http.StatusFound)
return http.StatusFound, nil return http.StatusFound, nil
......
...@@ -3,6 +3,7 @@ package github ...@@ -3,6 +3,7 @@ package github
import ( import (
"errors" "errors"
"net/http" "net/http"
"time"
"github.com/nsheridan/cashier/server/auth" "github.com/nsheridan/cashier/server/auth"
"github.com/nsheridan/cashier/server/config" "github.com/nsheridan/cashier/server/config"
...@@ -83,7 +84,16 @@ func (c *Config) StartSession(state string) *auth.Session { ...@@ -83,7 +84,16 @@ func (c *Config) StartSession(state string) *auth.Session {
// Exchange authorizes the session and returns an access token. // Exchange authorizes the session and returns an access token.
func (c *Config) Exchange(code string) (*oauth2.Token, error) { func (c *Config) Exchange(code string) (*oauth2.Token, error) {
return c.config.Exchange(oauth2.NoContext, code) t, err := c.config.Exchange(oauth2.NoContext, code)
if err != nil {
return nil, err
}
// Github tokens don't have an expiry. Set one so that the session expires
// after a period.
if t.Expiry.Unix() <= 0 {
t.Expiry = time.Now().Add(1 * time.Hour)
}
return t, nil
} }
// Username retrieves the username portion of the user's email address. // Username retrieves the username portion of the user's email address.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment