Authentication Flows
To authenticate you will need an access token from the fediverse instance you are connecting to. Minimal-activitypub supports two different ways of generating access tokens. One requires that the Username and password is supplied, the other generates an Authorization URL that a user needs to visit to generate an authorization code that then needs to be supplied to minimal-activitypub to ultimately generate an access token.
Username and password
The sample code below shows the steps needed to generate an access token with having a user visit a URL and then input the authorization code provided on that URL to ultimately generate an access token.
1from minimal_activitypub.client_2_server import ActivityPub
2from httpx import AsyncClient
3
4async def get_access_token(mastodon_domain, user_name, password):
5
6 async with AsyncClient(http2=True) as client:
7 # Create app
8 client_id, client_secret = await ActivityPub.create_app(
9 instance_url=mastodon_domain,
10 client=client,
11 )
12
13
14 # Get access token
15 access_token = await ActivityPub.get_auth_token(
16 instance_url=instance,
17 username=user_name,
18 password=password,
19 client=client,
20 )
Method Signatures
Following are the method signatures used in the above examples.