feat(BRIDGE-154): include access token when refreshing

This commit is contained in:
ElectroNafta
2025-02-17 13:12:57 +01:00
committed by ElectroNafta
parent c2689a2c0c
commit 2e531f21de
3 changed files with 6 additions and 3 deletions

View File

@@ -178,7 +178,7 @@ func (c *Client) authRefresh(ctx context.Context) error {
c.hookLock.RLock()
defer c.hookLock.RUnlock()
auth, err := c.m.authRefresh(ctx, c.uid, c.ref)
auth, err := c.m.authRefresh(ctx, c.uid, c.ref, c.acc)
if err != nil {
if respErr, ok := err.(*resty.ResponseError); ok {

View File

@@ -5,6 +5,7 @@ import (
"context"
"encoding/base64"
"errors"
"github.com/ProtonMail/go-srp"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/go-resty/resty/v2"
@@ -19,7 +20,7 @@ func (m *Manager) NewClient(uid, acc, ref string) *Client {
func (m *Manager) NewClientWithRefresh(ctx context.Context, uid, ref string) (*Client, Auth, error) {
c := newClient(m, uid)
auth, err := m.authRefresh(ctx, uid, ref)
auth, err := m.authRefresh(ctx, uid, ref, "")
if err != nil {
return nil, Auth{}, err
}
@@ -105,7 +106,7 @@ func (m *Manager) auth(ctx context.Context, req AuthReq, hv *APIHVDetails) (Auth
return res.Auth, nil
}
func (m *Manager) authRefresh(ctx context.Context, uid, ref string) (Auth, error) {
func (m *Manager) authRefresh(ctx context.Context, uid, ref, acc string) (Auth, error) {
state, err := crypto.RandomToken(32)
if err != nil {
return Auth{}, err
@@ -118,6 +119,7 @@ func (m *Manager) authRefresh(ctx context.Context, uid, ref string) (Auth, error
GrantType: "refresh_token",
RedirectURI: "https://protonmail.ch",
State: string(state),
AccessToken: acc,
}
var res struct {

View File

@@ -97,6 +97,7 @@ type AuthRefreshReq struct {
GrantType string
RedirectURI string
State string
AccessToken string `json:",omitempty"`
}
type AuthSession struct {