Skip to content

Commit

Permalink
Change OAuth complete timeout to 2 minutes (#606)
Browse files Browse the repository at this point in the history
* change oauth completetimeout to 5 minutes

* change timeout to 2 minutes
  • Loading branch information
mickmister authored Dec 2, 2022
1 parent d7f6701 commit a01cb87
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const (
// TokenTTL is the OAuth token expiry duration in seconds
TokenTTL = 10 * 60

requestTimeout = 30 * time.Second
requestTimeout = 30 * time.Second
oauthCompleteTimeout = 2 * time.Minute
)

type OAuthState struct {
Expand Down Expand Up @@ -385,7 +386,10 @@ func (p *Plugin) completeConnectUserToGitHub(c *Context, w http.ResponseWriter,

conf := p.getOAuthConfig(state.PrivateAllowed)

tok, err := conf.Exchange(c.Ctx, code)
ctx, cancel := context.WithTimeout(context.Background(), oauthCompleteTimeout)
defer cancel()

tok, err := conf.Exchange(ctx, code)
if err != nil {
c.Log.WithError(err).Warnf("Failed to exchange oauth code into token")

Expand All @@ -395,7 +399,7 @@ func (p *Plugin) completeConnectUserToGitHub(c *Context, w http.ResponseWriter,
}

githubClient := p.githubConnectToken(*tok)
gitUser, _, err := githubClient.Users.Get(c.Ctx, "")
gitUser, _, err := githubClient.Users.Get(ctx, "")
if err != nil {
c.Log.WithError(err).Warnf("Failed to get authenticated GitHub user")

Expand Down

0 comments on commit a01cb87

Please sign in to comment.