1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-11-03 04:17:21 -05:00

Add api endpoint for registring an account

This commit is contained in:
Ivan Habunek 2022-11-22 10:41:37 +01:00
parent e03b80d0be
commit 1721558875
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -37,6 +37,38 @@ def create_app(domain, scheme='https'):
return http.anon_post(url, data).json() return http.anon_post(url, data).json()
def register_account(app, username, email, password, locale="en", agreement=True):
"""
Register an account
https://docs.joinmastodon.org/methods/accounts/#create
"""
token = fetch_app_token(app)["access_token"]
url = f"{app.base_url}/api/v1/accounts"
headers = {"Authorization": f"Bearer {token}"}
data = {
"username": username,
"email": email,
"password": password,
"agreement": agreement,
"locale": locale
}
return http.anon_post(url, data=data, headers=headers).json()
def fetch_app_token(app):
data = {
"client_id": app.client_id,
"client_secret": app.client_secret,
"grant_type": "client_credentials",
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
"scope": "read write"
}
return http.anon_post(f"{app.base_url}/oauth/token", data).json()
def login(app, username, password): def login(app, username, password):
url = app.base_url + '/oauth/token' url = app.base_url + '/oauth/token'