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:
parent
e03b80d0be
commit
1721558875
32
toot/api.py
32
toot/api.py
@ -37,6 +37,38 @@ def create_app(domain, scheme='https'):
|
||||
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):
|
||||
url = app.base_url + '/oauth/token'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user