6.3. Revoke access from a user¶
Suppose user Alice owns a file named "file.txt"
and shared the file with
Bob.
alice, _ := client.InitUser("user_alice", "password1")
bob, _ := client.InitUser("user_bob", "password2")
alice.StoreFile("file.txt", []byte("content"))
invitationPtr, _ := alice.CreateInvitation("file.txt", "user_bob")
bob.AcceptInvitation(aliceUsername, invitationPtr, "from_alice.txt")
After accepting the invitation from Alice, Bob will be authorized to access Alice’s file under the filename “from_alice.txt”.
_, err := bob.LoadFile("from_alice.txt")
// err SHOULD be nil
err := bob.StoreFile("from_alice.txt", new_file_data)
// err SHOULD be nil
err := bob.AppendToFile("from_alice.txt", []byte("some more stuff"))
// err SHOULD be nil
Next, Alice revokes Bob’s permission to this file:
alice.RevokeAccess("file.txt", bobUsername)
Now, Bob is no longer authorized to access the file. Alice is always authorized to access the file because Alice is the owner. The client must ensure that Bob cannot use the client API to access the file.
alice_data, err := alice.LoadFile("file.txt")
// err SHOULD be nil
err := alice.StoreFile("file.txt", []byte("new stuff"))
// err SHOULD be nil
err := alice.AppendToFile("file.txt", []byte("some more stuff"))
// err SHOULD be nil
_, err := bob.LoadFile("from_alice.txt")
// err SHOULD NOT be nil
err := bob.StoreFile("from_alice.txt", new_file_data)
// err SHOULD NOT be nil
err := bob.AppendToFile("from_alice.txt", []byte("some more stuff"))
// err SHOULD NOT be nil