Skip to content

Commit

Permalink
Merge pull request #921 from kozl/master
Browse files Browse the repository at this point in the history
Fix authorization on methods which uses get requests
  • Loading branch information
kanata2 authored Apr 17, 2021
2 parents e0d14cc + c9d112a commit 158d3e0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ func (api *Client) ListEventAuthorizationsContext(ctx context.Context, eventCont

func (api *Client) UninstallApp(clientID, clientSecret string) error {
values := url.Values{
"token": {api.token},
"client_id": {clientID},
"client_secret": {clientSecret},
}

response := SlackResponse{}

err := api.getMethod(context.Background(), "apps.uninstall", values, &response)
err := api.getMethod(context.Background(), "apps.uninstall", api.token, values, &response)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ func (api *Client) GetPermalink(params *PermalinkParameters) (string, error) {
// GetPermalinkContext returns the permalink for a message using a custom context.
func (api *Client) GetPermalinkContext(ctx context.Context, params *PermalinkParameters) (string, error) {
values := url.Values{
"token": {api.token},
"channel": {params.Channel},
"message_ts": {params.Ts},
}
Expand All @@ -754,7 +753,7 @@ func (api *Client) GetPermalinkContext(ctx context.Context, params *PermalinkPar
Permalink string `json:"permalink"`
SlackResponse
}{}
err := api.getMethod(ctx, "chat.getPermalink", values, &response)
err := api.getMethod(ctx, "chat.getPermalink", api.token, values, &response)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,9 @@ type UserPrefs struct {
}

func (api *Client) GetUserPrefs() (*UserPrefsCarrier, error) {
values := url.Values{"token": {api.token}}
response := UserPrefsCarrier{}

err := api.getMethod(context.Background(), "users.prefs.get", values, &response)
err := api.getMethod(context.Background(), "users.prefs.get", api.token, url.Values{}, &response)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@ func postForm(ctx context.Context, client httpClient, endpoint string, values ur
return doPost(ctx, client, req, newJSONParser(intf), d)
}

func getResource(ctx context.Context, client httpClient, endpoint string, values url.Values, intf interface{}, d Debug) error {
func getResource(ctx context.Context, client httpClient, endpoint, token string, values url.Values, intf interface{}, d Debug) error {
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

req.URL.RawQuery = values.Encode()

return doPost(ctx, client, req, newJSONParser(intf), d)
Expand Down
4 changes: 2 additions & 2 deletions slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ func (api *Client) postMethod(ctx context.Context, path string, values url.Value
}

// get a slack web method.
func (api *Client) getMethod(ctx context.Context, path string, values url.Values, intf interface{}) error {
return getResource(ctx, api.httpclient, api.endpoint+path, values, intf, api)
func (api *Client) getMethod(ctx context.Context, path string, token string, values url.Values, intf interface{}) error {
return getResource(ctx, api.httpclient, api.endpoint+path, token, values, intf, api)
}

0 comments on commit 158d3e0

Please sign in to comment.