Skip to Content
defold-typescript libraries
widgrensitasobi-defold

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
    1. Pick a release from widgrensit/asobi-defold releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as api_auth from "asobi.api.auth"

Functions

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 to username.
  • callback?: HttpCallback — Receives the token pair and player_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 and player_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 and player_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 and player_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.

  1. (client: Client, callback?: HttpCallback)

    Parameters

    • client: Client — The client.
    • callback?: HttpCallback — Receives the token pair and player_id, or the error.
  2. (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 to asobi.device.load_or_create.
    • callback?: HttpCallback — Receives the token pair and player_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 and player_id, or the error.

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.

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.

On this page