Skip to content

Issue a ticket and open the web page

Right before opening a web page, the app client obtains a ticket and opens the web page with a URL that has the ticket attached. For the overall flow, see Pass the login state to web pages.

Issue a ticket

The app client obtains a ticket right before opening the web page. Include the Client ID used for login in the request. A ticket cannot be redeemed after 60 seconds, so do not obtain a ticket in advance.

Note

Open the web page as soon as the ticket is received. If a ticket that has not been redeemed yet exists, the Hive Axyl authentication server returns that ticket again instead of a new ticket, and its remaining validity time is shorter than 60 seconds. After a new login in the app or a refresh of the app's tokens, a new ticket is issued.

Method

IssueTicketAsync

Call IssueTicketAsync() to obtain a ticket. Put only the Client ID used for login (token issuance) in the request. The Hive Axyl SDK adds the user access token and the App ID to the request.

Call parameters

Field name Type Required Description
request TicketIssueRequest Required The ticket issuance request
context ApiCallContext? Optional A per-call settings object. If omitted, the default values are used.

TicketIssueRequest

Field name Type Required Description
ClientId string Required The Client ID used for login (token issuance). Up to 32 characters

Call example

For the result model and handling principles of the common failure (Failure) returned when a request cannot be performed, see Common error handling.

using Hive.Axyl.Core;
using Hive.Axyl.Auth;
using UnityEngine;

// token: ITokenService registered during module initialization
ITokenService token = HiveCore.Resolve<ITokenService>();

TokenIssueTicketResult result = await token.IssueTicketAsync(new TicketIssueRequest
{
    ClientId = clientId,
});

switch (result)
{
    case TokenIssueTicketResult.Success success:
        // success.Data : TicketIssueResponseData
        break;

    case TokenIssueTicketResult.AppNotFound:
        // app_not_found
        break;

    case TokenIssueTicketResult.InvalidClient:
        // invalid_client
        break;

    case TokenIssueTicketResult.InvalidGatewayContext:
        // invalid_gateway_context
        break;

    case TokenIssueTicketResult.AppIdMismatch:
        // app_id_mismatch
        break;

    case TokenIssueTicketResult.InvalidToken:
        // invalid_token
        break;

    case TokenIssueTicketResult.IpBlocked:
        // ip_blocked
        break;

    case TokenIssueTicketResult.TicketUnavailable:
        // ticket_unavailable
        break;

    // Handle common failures (network and server errors, common Failure codes)
    case TokenIssueTicketResult.Failure failure:
        HiveError err = failure.Problem;
        Debug.LogError($"[{err.Code}] The request failed");
        break;

    // A new result that this SDK version does not know: record it, and then treat it as a failure.
    case TokenIssueTicketResult.UnknownOutcome:
        Debug.LogWarning("[Token] Unknown result");
        break;

    // Safety net: unhandled results
    default:
        Debug.LogWarning($"Unhandled result: {result.GetType().Name}");
        break;
}

Response data

On success, the ticket is in the Data (TicketIssueResponseData) of TokenIssueTicketResult.Success.

Field name Type Required Description
Data.Ticket string Required A single-use ticket (36-character UUID). Append it as is, without encoding, to the ticket query parameter of the web page URL
Data.ExpiresIn long Required Seconds left until the ticket expires (1-60). The web service server has to finish redeeming the ticket within this time, so open the web page as soon as you receive it
Data.Meta string? Optional Additional information sent by the Hive Axyl server. A raw JSON string; null if there is no additional information

Response status

The returned TokenIssueTicketResult is one of the cases below. InvalidClient, AppNotFound, AppIdMismatch, and InvalidGatewayContext mean you need to check the app settings or the session. In these cases, tell the user that the web page cannot be opened.

When the access token has expired, the Hive Axyl SDK refreshes the token automatically and sends the request again. If the refresh fails, Failure is returned. For the automatic refresh settings and how to handle refresh failures, see Refresh access tokens automatically.

Result case Description App client action
Success The ticket was issued. Data holds the ticket. Go to Open the web page right away
InvalidToken This access token can no longer be used. Have the user log in again and start over
IpBlocked The request was restricted by the IP restriction policy. Even after the block is lifted, tokens issued before it may not be usable. Have the user log in again. If login is restricted, follow Usage restriction
InvalidClient No ticket can be issued for this Client ID. Check that the request uses the Client ID used for login
AppNotFound The app information cannot be found. Check the app registration status in the console
AppIdMismatch The requesting app differs from the app the access token was issued to. Check that the App ID used to initialize the Hive Axyl SDK is the App ID of the app the user logged in to
InvalidGatewayContext The request used a token that is not a user access token. Check that the session was set with the tokens issued by the user's login
TicketUnavailable A ticket cannot be issued right now. Do not retry immediately; tell the user that the web page cannot be opened
Failure Common Failure. A missing or malformed ClientId (invalid_parameter), a missing required field (missing_field), a missing X-App-Id header (missing_app_id), and server errors (5xx) also fall into this case. The cause code is in Failure.Problem.ExternalCode. See Common error handling. For invalid_parameter, check ClientId (up to 32 characters). For missing_field or missing_app_id, check that the App ID was set when initializing the Hive Axyl SDK. Tell the user that the web page cannot be opened
UnknownOutcome A new result unknown to this SDK version. Handle it as a failure and record Code. For the handling criteria, see Unknown results.

Open the web page

The app client adds the issued ticket, without URL encoding, as the ticket query parameter of the web page URL and opens the web page. The rest of the web page URL follows the format defined by each web service.

https://{web-service-host}/{path}?ticket={ticket}

Next steps