From 4e5e665dffd47cd02a560833ff41b8ab9ba191de Mon Sep 17 00:00:00 2001 From: Daniil Suvorov Date: Sat, 16 Jul 2022 10:31:48 +0300 Subject: [PATCH] feat(api): use Authorization Bearer resolved #206 --- api/api.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/api/api.go b/api/api.go index dfc4afaf..c1fb3dea 100644 --- a/api/api.go +++ b/api/api.go @@ -203,10 +203,13 @@ func buildQuery(sliceParams ...Params) (context.Context, url.Values) { for _, params := range sliceParams { for key, value := range params { - if key != ":context" { - query.Set(key, FmtValue(value, 0)) - } else { + switch key { + case "access_token": + continue + case ":context": ctx = value.(context.Context) + default: + query.Set(key, FmtValue(value, 0)) } } } @@ -255,6 +258,9 @@ func (vk *VK) DefaultHandler(method string, sliceParams ...Params) (Response, er acceptEncoding = "zstd" } + token := sliceParams[len(sliceParams)-1]["access_token"].(string) + req.Header.Set("Authorization", "Bearer "+token) + req.Header.Set("User-Agent", vk.UserAgent) req.Header.Set("Content-Type", "application/x-www-form-urlencoded")