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"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"miniflux.app/v2/internal/urllib"
|
||||
|
@ -74,14 +73,15 @@ func (c *Client) CreateLink(entryURL, entryTitle string) error {
|
|||
}
|
||||
|
||||
func (c *Client) generateBearerToken() string {
|
||||
header := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(`{"typ":"JWT", "alg":"HS256"}`)), "=")
|
||||
payload := strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf(`{"iat": %d}`, time.Now().Unix()))), "=")
|
||||
header := base64.RawURLEncoding.EncodeToString([]byte(`{"typ":"JWT","alg":"HS512"}`))
|
||||
payload := base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf(`{"iat":%d}`, time.Now().Unix())))
|
||||
data := header + "." + payload
|
||||
|
||||
mac := hmac.New(sha512.New, []byte(c.apiSecret))
|
||||
mac.Write([]byte(header + "." + payload))
|
||||
signature := strings.TrimRight(base64.URLEncoding.EncodeToString(mac.Sum(nil)), "=")
|
||||
mac.Write([]byte(data))
|
||||
signature := base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
|
||||
|
||||
return header + "." + payload + "." + signature
|
||||
return data + "." + signature
|
||||
}
|
||||
|
||||
type addLinkRequest struct {
|
||||
|
|
Loading…
Reference in a new issue