interface MAGES::IAuthenticationAPI

Overview

An interface for the authentication clients. More…

interface IAuthenticationAPI
{
    // properties

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

    // methods

    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
    );
};

// direct descendants

class DeveloperAuthentication;
class UserAuthenticationModule;

Detailed Documentation

An interface for the authentication clients.

Properties

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.

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.

Methods

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

Perform Login.

Parameters:

username

The username.

password

The password.

Returns:

The request status code.

void LogOut()

Performs log out.

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.

Task<ResponseStatusCode> RequestLicense()

Requests a license.

Returns:

The request status code.

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.

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.

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.

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.

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.

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.