Skip to content

Commit d029802

Browse files
authored
Merge pull request #47 from eclipse-biscuit/push-mkyzunypovru
third-party blocks: type stubs and documentation
2 parents 3842026 + e558396 commit d029802

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

biscuit_auth.pyi

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,38 @@ class Biscuit:
178178
# :rtype: Biscuit
179179
def append(self, block: BlockBuilder) -> Biscuit: ...
180180

181+
# Create a new `Biscuit` by appending a third-party attenuation block
182+
#
183+
# :param external_key: the public key of the third-party that signed the block.
184+
# :type external_key: PublicKey
185+
# :param block: the third party block to append
186+
# :type block: ThirdPartyBlock
187+
# :return: the attenuated biscuit
188+
# :rtype: Biscuit
189+
def append_third_party(
190+
self,
191+
external_key: PublicKey,
192+
block: ThirdPartyBlock,
193+
) -> Biscuit: ...
194+
195+
# Create a third-party request for generating third-party blocks.
196+
#
197+
# :return: the third-party request
198+
# :rtype: ThirdPartyRequest
199+
def third_party_request(self) -> ThirdPartyRequest: ...
200+
181201
# The revocation ids of the token, encoded as hexadecimal strings
182202
@property
183203
def revocation_ids(self) -> List[str]: ...
184204

205+
# Get the external key of a block if it exists
206+
#
207+
# :param index: the block index
208+
# :type index: int
209+
# :return: the public key if it exists
210+
# :rtype: str | None
211+
def block_external_key(self, index: int) -> str | None: ...
212+
185213
class AuthorizerBuilder:
186214
# Create a new authorizer from a datalog snippet and optional parameter values
187215
#
@@ -597,3 +625,23 @@ class UnverifiedBiscuit:
597625
@property
598626
def revocation_ids(self) -> List[str]: ...
599627
def verify(self, root: PublicKey) -> Biscuit: ...
628+
629+
class ThirdPartyRequest:
630+
# Create a third-party block
631+
#
632+
# :param private_key: the third-party's private key used to sign the block
633+
# :type external_key: PrivateKey
634+
# :param block: the block builder to be signed
635+
# :type block: BlockBuilder
636+
# :return: a signed block that can be appended to a Biscuit
637+
# :rtype: ThirdPartyBlock
638+
#
639+
# :note: this method consumes the `ThirdPartyRequest` object.
640+
def create_block(
641+
self,
642+
private_key: PrivateKey,
643+
block: BlockBuilder
644+
) -> ThirdPartyBlock: ...
645+
646+
class ThirdPartyBlock:
647+
pass

docs/basic-use.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,12 @@ Save and load snapshots
117117

118118
>>> snapshot = authorizer.base64_snapshot()
119119
>>> parsed = Authorizer.from_base64_snapshot(snapshot)
120+
121+
Third-party blocks
122+
------------------
123+
124+
>>> external_keypair = KeyPair()
125+
>>> third_party_request = token.third_party_request()
126+
>>> new_block = BlockBuilder("external(true)")
127+
>>> third_party_block = third_party_request.create_block(external_keypair.private_key, new_block)
128+
>>> new_biscuit = token.append_third_party(external_keypair.public_key, third_party_block)

0 commit comments

Comments
 (0)