Fix and simplify shaarli's integration
- The jwt token was declared as using HS256 as algorithm, but was using HS512. - No need to base64-encode then remove the padding when we can simply encode without padding. - Factorize the header+payload concatenation as data Odds are that this integration was broken from the start (HS512 vs HS256), so I'm not sure if it's better to add tests or to simply get rid of it.
This commit is contained in:
parent
648b9a8f6f
commit
f4746a7306
1 changed files with 6 additions and 6 deletions
|
@ -11,7 +11,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"miniflux.app/v2/internal/urllib"
|
"miniflux.app/v2/internal/urllib"
|
||||||
|
@ -74,14 +73,15 @@ func (c *Client) CreateLink(entryURL, entryTitle string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) generateBearerToken() string {
|
func (c *Client) generateBearerToken() string {
|
||||||
header := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(`{"typ":"JWT", "alg":"HS256"}`)), "=")
|
header := base64.RawURLEncoding.EncodeToString([]byte(`{"typ":"JWT","alg":"HS512"}`))
|
||||||
payload := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf(`{"iat": %d}`, time.Now().Unix()))), "=")
|
payload := base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf(`{"iat":%d}`, time.Now().Unix())))
|
||||||
|
data := header + "." + payload
|
||||||
|
|
||||||
mac := hmac.New(sha512.New, []byte(c.apiSecret))
|
mac := hmac.New(sha512.New, []byte(c.apiSecret))
|
||||||
mac.Write([]byte(header + "." + payload))
|
mac.Write([]byte(data))
|
||||||
signature := strings.TrimRight(base64.URLEncoding.EncodeToString(mac.Sum(nil)), "=")
|
signature := base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
|
||||||
|
|
||||||
return header + "." + payload + "." + signature
|
return data + "." + signature
|
||||||
}
|
}
|
||||||
|
|
||||||
type addLinkRequest struct {
|
type addLinkRequest struct {
|
||||||
|
|
Loading…
Reference in a new issue