diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-18 11:28:43 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-18 11:28:43 +0300 |
| commit | 9525b8c9a3f714235c8e591f3eddd4c05ed791da (patch) | |
| tree | e0df3658d353649a7a23d0109b3f6924bba10af9 /internal/platforms/linkedin/oauth2/oauth2.go | |
| parent | 56b272ca1b678023c51d730acda04e56867ad141 (diff) | |
use context in oauth2
Diffstat (limited to 'internal/platforms/linkedin/oauth2/oauth2.go')
| -rw-r--r-- | internal/platforms/linkedin/oauth2/oauth2.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/internal/platforms/linkedin/oauth2/oauth2.go b/internal/platforms/linkedin/oauth2/oauth2.go index 21caf92..8c03761 100644 --- a/internal/platforms/linkedin/oauth2/oauth2.go +++ b/internal/platforms/linkedin/oauth2/oauth2.go @@ -22,6 +22,7 @@ var ( oauthAccessToken string oauthPersonID string errCh chan error + globalCtx context.Context ) func getOauthPersonID(token *oauth2.Token) (string, error) { @@ -72,8 +73,7 @@ func oauthCallbackHandler(w http.ResponseWriter, r *http.Request) { code := r.URL.Query().Get("code") log.Println("Exchanging OAuth2 token") - // TODO: Insert the propper context - token, err := oauthConfig.Exchange(context.Background(), code) + token, err := oauthConfig.Exchange(globalCtx, code) if err != nil { _, _ = w.Write([]byte(err.Error())) errCh <- err @@ -90,7 +90,7 @@ func oauthCallbackHandler(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("Successfully fetched LinkedIn person ID\n")) } -func LinkedInCreds(args config.Args) (string, string, error) { +func LinkedInCreds(ctx context.Context, args config.Args) (string, string, error) { secrets := args.Secrets if secrets.LinkedInAccessToken != "" && secrets.LinkedInPersonID != "" { return secrets.LinkedInPersonID, secrets.LinkedInAccessToken, nil @@ -104,6 +104,7 @@ func LinkedInCreds(args config.Args) (string, string, error) { Endpoint: linkedin.Endpoint, } errCh = make(chan error) + globalCtx = ctx http.HandleFunc("/", oauthIndexHandler) http.HandleFunc("/callback", oauthCallbackHandler) |
