Skip to content

Commit

Permalink
Fix auth hub by removing cached jwt after deleting keys (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmerrill6 authored Sep 2, 2020
1 parent b81ddb8 commit fa1c253
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
7 changes: 4 additions & 3 deletions core/space/services/services_keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ func (s *Space) GetMnemonic(ctx context.Context) (string, error) {
}

func (s *Space) DeleteKeypair(ctx context.Context) error {
err := s.keychain.DeleteKeypair()
if err != nil {
if err := s.keychain.DeleteKeypair(); err != nil {
return err
}

// Tell the textile client to stop operations
s.tc.RemoveKeys()
if err := s.tc.RemoveKeys(); err != nil {
return err
}

return nil
}
8 changes: 7 additions & 1 deletion core/textile/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,14 @@ func (tc *textileClient) healthcheck(ctx context.Context) {
}
}

func (tc *textileClient) RemoveKeys() {
func (tc *textileClient) RemoveKeys() error {
if err := tc.hubAuth.ClearCache(); err != nil {
return err
}

tc.isInitialized = false
tc.isConnectedToHub = false
tc.keypairDeleted <- true

return nil
}
6 changes: 6 additions & 0 deletions core/textile/hub/hub_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type AuthTokens struct {
type HubAuth interface {
GetTokensWithCache(ctx context.Context) (*AuthTokens, error)
GetHubContext(ctx context.Context) (context.Context, error)
ClearCache() error
}

type hub struct {
Expand Down Expand Up @@ -143,6 +144,11 @@ func (h *hub) storeTokens(tokens *inMessageTokenValue) error {
return nil
}

// Removes the stored tokens
func (h *hub) ClearCache() error {
return h.st.Remove([]byte(tokensStoreKey))
}

func (h *hub) getTokensThroughChallenge(ctx context.Context) (*inMessageTokenValue, error) {
log.Debug("Token Challenge: Connecting through websocket")
conn, err := websocket.Dial(h.cfg.GetString(config.SpaceServicesHubAuthURL, ""), "", "http://localhost/")
Expand Down
2 changes: 1 addition & 1 deletion core/textile/textile.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Client interface {
WaitForReady() chan bool
Start(ctx context.Context, cfg config.Config) error
ShareFilesViaPublicKey(ctx context.Context, bucketName string, paths []string, pubkeys []crypto.PubKey) error
RemoveKeys()
RemoveKeys() error
}

type Buckd interface {
Expand Down
14 changes: 14 additions & 0 deletions mocks/HubAuth.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions mocks/mock_textile_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa1c253

Please sign in to comment.