widgrensit/asobi-defold/asobi.api.auth
asobi sign-in over REST: accounts, OAuth, guest devices, linked providers and the token
pair. A project reaches it as client.auth.
- GitHub: widgrensit/asobi-defold — pinned to
v1.18.1- Pick a release from widgrensit/asobi-defold releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as api_auth from "asobi.api.auth"
- Pick a release from widgrensit/asobi-defold releases and add its Source code (zip) URL (or a packaged
Functions
register(client: Client, username: string, password: string, display_name?: string, callback?: HttpCallback)login(client: Client, username: string, password: string, callback?: HttpCallback)oauth(client: Client, provider: string, token: string, callback?: HttpCallback)guest(client: Client, device_id: string, device_secret: string, callback?: HttpCallback)guest_device(2 overloads)upgrade_guest(client: Client, username: string, password: string, callback?: HttpCallback)link_provider(client: Client, provider: string, token: string, callback?: HttpCallback)unlink_provider(client: Client, provider: string, callback?: HttpCallback)refresh(client: Client, callback?: HttpCallback)logout(client: Client, callback?: HttpCallback)
register(client: Client, username: string, password: string, display_name?: string, callback?: HttpCallback)
Creates an account and signs it in. On success it stores the returned tokens with
client.set_tokens and sets client.player_id.
Parameters
client:Client— The client.username:string— The account's username.password:string— The account's password.display_name?:string— The name other players see. Defaults tousername.callback?:HttpCallback— Receives the token pair andplayer_id, or the error.
login(client: Client, username: string, password: string, callback?: HttpCallback)
Signs an account in. On success it stores the returned tokens with client.set_tokens
and sets client.player_id.
Parameters
client:Client— The client.username:string— The account's username.password:string— The account's password.callback?:HttpCallback— Receives the token pair andplayer_id, or the error.
oauth(client: Client, provider: string, token: string, callback?: HttpCallback)
Signs in with a token from an OAuth provider. On success it stores the returned tokens
with client.set_tokens and sets client.player_id.
Parameters
client:Client— The client.provider:string— The provider's name.token:string— The provider's token.callback?:HttpCallback— Receives the token pair andplayer_id, or the error.
guest(client: Client, device_id: string, device_secret: string, callback?: HttpCallback)
Signs a guest in with a device credential pair. On success it stores the returned tokens
with client.set_tokens and sets client.player_id.
Parameters
client:Client— The client.device_id:string— The device id.device_secret:string— The device secret.callback?:HttpCallback— Receives the token pair andplayer_id, or the error.
guest_device(2 overloads)
Loads the saved device credential pair, or generates and saves one, and signs a guest in
with it through guest.
(client: Client, callback?: HttpCallback)Parameters
client:Client— The client.callback?:HttpCallback— Receives the token pair andplayer_id, or the error.
(client: Client, opts: DeviceOptions | undefined, callback?: HttpCallback)Parameters
client:Client— The client.opts:DeviceOptions | undefined— Where the pair is saved and how it is generated, passed toasobi.device.load_or_create.callback?:HttpCallback— Receives the token pair andplayer_id, or the error.
upgrade_guest(client: Client, username: string, password: string, callback?: HttpCallback)
Turns the signed-in guest into an account with a username and password. On success it
stores the returned tokens with client.set_tokens and sets client.player_id.
Parameters
client:Client— The client.username:string— The account's username.password:string— The account's password.callback?:HttpCallback— Receives the token pair andplayer_id, or the error.
link_provider(client: Client, provider: string, token: string, callback?: HttpCallback)
Links an OAuth provider to the signed-in account.
Parameters
client:Client— The client.provider:string— The provider's name.token:string— The provider's token.callback?:HttpCallback— Receives the server's answer, or the error.
unlink_provider(client: Client, provider: string, callback?: HttpCallback)
Unlinks an OAuth provider from the signed-in account.
Parameters
client:Client— The client.provider:string— The provider's name.callback?:HttpCallback— Receives the server's answer, or the error.
refresh(client: Client, callback?: HttpCallback)
Exchanges the refresh token for a new token pair, which it stores with
client.set_tokens. The server accepts each refresh token once. An open realtime
connection re-authenticates with the new access token. asobi.http calls it on a 401.
Parameters
client:Client— The client.callback?:HttpCallback— Receives the new token pair, or the error.
logout(client: Client, callback?: HttpCallback)
Signs out, then forgets both tokens and client.player_id whether or not the server
answered with an error.
Parameters
client:Client— The client.callback?:HttpCallback— Receives the server's answer, or the error.