in fxa/core.py [0:0]
def create_account(self, email, password=None, stretchpwd=None, **kwds):
"""creates an account with email and password.
Note, the stretched password can also be provided. When doing this, and
using key_stretch_version=2, the format changes from a string to StrechedPassword
object
"""
keys = kwds.pop("keys", False)
if self.key_stretch_version == 2:
spwd = StretchedPassword(2, email, create_salt(2, hexlify(token_bytes(16))),
password, stretchpwd)
kb = token_bytes(32)
body = {
"email": email,
"authPW": spwd.get_auth_pw_v1(),
"wrapKb": spwd.get_wrapkb_v1(kb),
"authPWVersion2": spwd.get_auth_pw_v2(),
"wrapKbVersion2": spwd.get_wrapkb_v2(kb),
"clientSalt": spwd.v2_salt,
}
else:
spwd = StretchedPassword(1, email, None, password, stretchpwd)
body = {
"email": email,
"authPW": spwd.get_auth_pw_v1(),
}
EXTRA_KEYS = ("service", "redirectTo", "resume", "preVerifyToken",
"preVerified")
for extra in kwds:
if extra in EXTRA_KEYS:
body[extra] = kwds[extra]
else:
msg = f"Unexpected keyword argument: {extra}"
raise TypeError(msg)
url = "/account/create"
if keys:
url += "?keys=true"
resp = self.apiclient.post(url, body)
if self.key_stretch_version == 2:
stretchpwd_final = spwd
key_fetch_token = resp.get('keyFetchTokenVersion2')
else:
stretchpwd_final = spwd.v1
key_fetch_token = resp.get('keyFetchToken')
# XXX TODO: somehow sanity-check the schema on this endpoint
return Session(
client=self,
email=email,
stretchpwd=stretchpwd_final,
uid=resp["uid"],
token=resp["sessionToken"],
key_fetch_token=key_fetch_token,
verified=False,
auth_timestamp=resp["authAt"],
)