class MAGES::UserAuthenticationModule

Overview

The base user authentication module. More…

class UserAuthenticationModule:
    public MAGES::HubModule,
    public MAGES::IAuthenticationAPI
{
public:
    // properties

    bool OfflineMode;
    bool RequireLoginAndLicenseBeforeOperationStart;
    string ProductCode;
    GameObject AuthenticationUI;
    bool IsLoggedIn;
    bool HasActiveLicense;
    UnityEvent LoggedIn;
    UnityEvent LoggedOut;
    UnityEvent LicenseGranted;
    UnityEvent LicenseRevoked;

    // methods

    virtual async Task<ResponseStatusCode> LogIn(string username, string password);
    virtual void LogOut();

    virtual async Task<ResponseStatusCode> LogInAndRequestLicense(
        string username,
        string password
    );

    virtual async Task<ResponseStatusCode> RequestLicense();
    virtual async Task<(ResponseStatusCode, User?)> GetUser(bool forceFetchFromServer = false);
    virtual async Task<(ResponseStatusCode, License?)> GetActiveLicense(bool forceFetchFromServer = false);

    virtual async Task SendRequestAsync(
        HttpRequestMessage msg,
        HttpCompletionOption completionOption,
        CancellationToken cancellationToken
    );

    virtual async Task SendRequestAsync(HttpRequestMessage msg);

    virtual Task SendRequestAsync(
        HttpRequestMessage msg,
        HttpCompletionOption completionOption
    );

    virtual Task SendRequestAsync(
        HttpRequestMessage msg,
        CancellationToken cancellationToken
    );
};

// direct descendants

class StubUserAuthentication;
class MAGESUserAuthentication;

Inherited Members

public:
    // properties

    int Version;
    UnityEvent LoggedIn;
    UnityEvent LoggedOut;
    UnityEvent LicenseGranted;
    UnityEvent LicenseRevoked;
    bool IsLoggedIn;
    bool HasActiveLicense;

    // methods

    void Startup();
    void Shutdown();
    virtual void UpdateModule(UpdatePhase updatePhase);
    Task<ResponseStatusCode> LogIn(string username, string password);
    void LogOut();

    Task<ResponseStatusCode> LogInAndRequestLicense(
        string username,
        string password
    );

    Task<ResponseStatusCode> RequestLicense();
    Task<(ResponseStatusCode, User?)> GetUser(bool forceFetchFromServer = false);
    Task<(ResponseStatusCode, License?)> GetActiveLicense(bool forceFetchFromServer = false);

    Task SendRequestAsync(
        HttpRequestMessage msg,
        HttpCompletionOption completionOption,
        CancellationToken cancellationToken
    );

    Task SendRequestAsync(HttpRequestMessage msg);

    Task SendRequestAsync(
        HttpRequestMessage msg,
        HttpCompletionOption completionOption
    );

    Task SendRequestAsync(
        HttpRequestMessage msg,
        CancellationToken cancellationToken
    );

Detailed Documentation

The base user authentication module.

Properties

bool OfflineMode

Gets or sets a value indicating whether the user is in offline mode. In offline mode, nothing is communicated to the server, as if the user had no internet connection.

bool RequireLoginAndLicenseBeforeOperationStart

Gets a value indicating whether the user must be logged in and a license to be granted before the operation starts.

string ProductCode

Gets the product code.

GameObject AuthenticationUI

Gets the authentication UI.

bool IsLoggedIn

Gets a value indicating whether a user is logged in.

bool HasActiveLicense

Gets a value indicating whether the user has activated a license.

UnityEvent LoggedIn

Gets or sets the event invoked immediately after a developer has logged in.

UnityEvent LoggedOut

Gets or sets the event invoked immediately after the developer gets logged out.

UnityEvent LicenseGranted

Gets or sets the event invoked immediately after the developer’s license is granted.

UnityEvent LicenseRevoked

Gets or sets the event invoked immediately after the developer’s license gets invalidated.

Methods

virtual async Task<ResponseStatusCode> LogIn(string username, string password)

Perform Login.

Parameters:

username

The username.

password

The password.

Returns:

The request status code.

virtual void LogOut()

Performs log out.

virtual async Task<ResponseStatusCode> LogInAndRequestLicense(
    string username,
    string password
)

Logs in and requests a license.

Parameters:

username

The username.

password

The password.

Returns:

The request status code.

virtual async Task<ResponseStatusCode> RequestLicense()

Requests a license.

Returns:

The request status code.

virtual async Task<(ResponseStatusCode, User?)> GetUser(bool forceFetchFromServer = false)

Gets the User Information.

Parameters:

forceFetchFromServer

If set to false and local cached data exists will return that. Otherwise, will request for new data from the server.

Returns:

The request status code and the logged in User, if any.

virtual async Task<(ResponseStatusCode, License?)> GetActiveLicense(bool forceFetchFromServer = false)

Gets the currently active license, or a new one if no active license is found.

Parameters:

forceFetchFromServer

If set to false and local cached data exists will return that. Otherwise, will request for new data from the server.

Returns:

The request status code and the currently active license, if any.

virtual async Task SendRequestAsync(
    HttpRequestMessage msg,
    HttpCompletionOption completionOption,
    CancellationToken cancellationToken
)

Adds the Authorization header and sends the web request. If the request fails due to an expired access token, it will try to refresh the token and retry the request.

Parameters:

msg

The HTTP request message to send.

completionOption

When the operation should complete (as soon as a response is available or after reading the whole response content).

cancellationToken

The cancellation token to cancel operation.

Returns:

The task object representing the asynchronous operation.

virtual async Task SendRequestAsync(HttpRequestMessage msg)

Adds the Authorization header and sends the web request. If the request fails due to an expired access token, it will try to refresh the token and retry the request.

Parameters:

msg

The HTTP request message to send.

Returns:

The task object representing the asynchronous operation.

virtual Task SendRequestAsync(
    HttpRequestMessage msg,
    HttpCompletionOption completionOption
)

Adds the Authorization header and sends the web request. If the request fails due to an expired access token, it will try to refresh the token and retry the request.

Parameters:

msg

The HTTP request message to send.

completionOption

When the operation should complete (as soon as a response is available or after reading the whole response content).

Returns:

The task object representing the asynchronous operation.

virtual Task SendRequestAsync(
    HttpRequestMessage msg,
    CancellationToken cancellationToken
)

Adds the Authorization header and sends the web request. If the request fails due to an expired access token, it will try to refresh the token and retry the request.

Parameters:

msg

The HTTP request message to send.

cancellationToken

The cancellation token to cancel operation.

Returns:

The task object representing the asynchronous operation.