diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2016-05-28 23:48:50 +0100 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2016-05-28 23:48:50 +0100 |
commit | 054e32ed3ab3d4102c9447ed0089387206587ed2 (patch) | |
tree | 283ebfcbd8ca5bd56d4c6765de7ff0ad724550f7 /server/auth | |
parent | 69973a0c0cea573d444d46b5ae69bebc1567a9b8 (diff) | |
parent | 54e3f0f7d25b67a310128a3cb7f888ea3ee44e2b (diff) |
Merge pull request #9 from nsheridan/github_auth
Set expiry time in the github auth package
Diffstat (limited to 'server/auth')
-rw-r--r-- | server/auth/github/github.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/server/auth/github/github.go b/server/auth/github/github.go index 192cd9d..d7a57af 100644 --- a/server/auth/github/github.go +++ b/server/auth/github/github.go @@ -3,6 +3,7 @@ package github import ( "errors" "net/http" + "time" "github.com/nsheridan/cashier/server/auth" "github.com/nsheridan/cashier/server/config" @@ -83,7 +84,16 @@ func (c *Config) StartSession(state string) *auth.Session { // Exchange authorizes the session and returns an access token. 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. |