Skip to content

Commit

Permalink
fix(server): fix incorrect use of context
Browse files Browse the repository at this point in the history
  • Loading branch information
MuXiu1997 committed Jan 30, 2023
1 parent ed30ab1 commit 788a2b0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/app/traefik-github-oauth-server/router/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,19 @@ func getAuthResult(app *server.App) gin.HandlerFunc {
}

func oAuthCodeToUser(ctx context.Context, oAuthConfig *oauth2.Config, code string) (*github.User, error) {
token, err := oAuthConfig.Exchange(ctx, code)
ctxExchange, cancelExchange := context.WithCancel(ctx)
defer cancelExchange()
token, err := oAuthConfig.Exchange(ctxExchange, code)
if err != nil {
return nil, err
}
gitHubApiHttpClient := oAuthConfig.Client(ctx, token)
ctxClient, cancelClient := context.WithCancel(ctx)
defer cancelClient()
gitHubApiHttpClient := oAuthConfig.Client(ctxClient, token)
gitHubApiClient := github.NewClient(gitHubApiHttpClient)
user, _, err := gitHubApiClient.Users.Get(ctx, "")
ctxGetUser, cancelGetUser := context.WithCancel(ctx)
defer cancelGetUser()
user, _, err := gitHubApiClient.Users.Get(ctxGetUser, "")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 788a2b0

Please sign in to comment.