创建 PasswordlessClient
实例:
from passwordless import (
PasswordlessClient,
PasswordlessClientBuilder,
PasswordlessOptions
)
class PasswordlessPythonSdkExample:
client: PasswordlessClient
def __init__(self):
options = PasswordlessOptions("your_api_secret")
self.client = PasswordlessClientBuilder(options).build()
import uuid
from passwordless import (
PasswordlessClient,
RegisterToken,
RegisteredToken
)
class PasswordlessPythonSdkExample:
client: PasswordlessClient
def get_register_token(self, alias: str) -> str:
# 从会话中获取现有用户 ID 或创建新用户
user_id = str(uuid.uuid4())
# 提供给 Api 的选项
register_token = RegisterToken(
user_id=user_id, # 您的用户 id
username=alias, # 例如用户电子邮件地址,将显示在浏览器 UI 中
aliases=[alias] # 可选:将此用户 ID 链接到别名(例如电子邮件地址)
)
response: RegisteredToken = self.client.register_token(register_token)
# 返回此令牌
return response.token
from passwordless import (
PasswordlessClient,
VerifySignIn,
VerifiedUser
)
class PasswordlessPythonSdkExample:
client: PasswordlessClient
def verify_sign_in_token(self, token: str) -> VerifiedUser:
verify_sign_in = VerifySignIn(token)
# 用户登录、设置 cookie 等
return self.client.sign_in(verify_sign_in)