Add api endpoint for registring an account

This commit is contained in:
Ivan Habunek 2022-11-22 10:41:37 +01:00
parent b15cb85a23
commit 44be9fd8bb
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
1 changed files with 32 additions and 0 deletions

View File

@ -37,6 +37,38 @@ def create_app(domain, scheme='https'):
return http.anon_post(url, json=json).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}"}
json = {
"username": username,
"email": email,
"password": password,
"agreement": agreement,
"locale": locale
}
return http.anon_post(url, json=json, headers=headers).json()
def fetch_app_token(app):
json = {
"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", json=json).json()
def login(app, username, password):
url = app.base_url + '/oauth/token'