Skip to content

Commit

Permalink
feat(BRIDGE-154): include access token when refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroNafta committed Feb 17, 2025
1 parent 67bd01a commit 0ce8541
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions manager_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions manager_auth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type AuthRefreshReq struct {
GrantType string
RedirectURI string
State string
AccessToken string `json:",omitempty"`
}

type AuthSession struct {
Expand Down

0 comments on commit 0ce8541

Please sign in to comment.