Skip to content

Search

Dokumentáció

Sign-in pages

platform::web_sign_in shows a provider's sign-in page over the game: the system sheet on Apple, a Custom Tab on Android, and the browser on desktop.

Ezen az oldalon

Signing in with a provider the platform has no native sheet for (Discord, GitHub, Google on iOS) means showing that provider's page. platform::web_sign_in shows it over the game, in the platform's own window for it.

Platform The page opens in It answers
iOS, macOS the system's sign-in sheet (ASWebAuthenticationSession) web_sign_in with the URL it ended on, or cancelled
Android a Custom Tab, in the default browser when it has them the same, once the redirect comes back
Windows, Linux, the web nothing: unsupported open the page with engine::open_url
pub async fn sign_in_page(url: str) -> str {
    let page = await task::wait(
        platform::web_sign_in(url, platform::WebSignInOptions { scheme: "com.studio.game" }),
    );
    if page["kind"].text() == platform::EVENT_UNSUPPORTED {
        engine::open_url(url);
        return "";
    }
    if page["kind"].text() == platform::EVENT_WEB_SIGN_IN {
        // com.studio.game:/done?code=…, the page's last URL.
        return page["url"].text();
    }
    ""
}
  • WebSignInOptions.scheme is the custom scheme the page ends on. The sheet shuts when it reaches it, and the answer carries that URL as url.
  • platform::close_web_sign_in() shuts the page once the game has what it opened it for, learned some other way. Its call answers cancelled, and on Android the game comes back in front of the tab.
  • platform::web_sign_in_state() reads how the last page stands without waiting: platform::PAGE_NONE, PAGE_OPEN, or the kind it answered. A game that polls its server meanwhile reads it to hear the player shut the page.

Android: the redirect

A Custom Tab hands the page's last URL back through an intent filter, so the scheme is declared at export:

[android]
schemes = ["com.studio.game"]

Each scheme is one intent filter on the game. The page must end on com.studio.game:/… for the tab to come back. A link on that scheme with no page open brings the game to the front, which does not read the link yet.

A server's sign-in

The page usually belongs to a server's OAuth flow. Gamend's starts at /api/v1/auth/<provider>, for any provider it has enabled: Google, Apple's web sign-in, Discord, GitHub, Facebook or Steam. A game polls the session it names, so it needs no redirect at all:

  • open the page with web_sign_in, or engine::open_url where that answers unsupported;
  • poll the server until the session is signed in;
  • call close_web_sign_in() to shut the page.

The platform module's reference lists every call.

Biztos vagy benne?