\UserAPIToken

Represents a user who either has or is in the process of acquiring an API access token via OAuth

Summary

Methods
Properties
Constants
__construct()
getToken()
setToken()
getAPIEndpoint()
setAPIEndpoint()
No public properties found
USER_TOKENS_TABLE
No protected methods found
No protected properties found
N/A
No private methods found
$consumerKey
$id
$sql
$token
$endpoint
N/A

Constants

USER_TOKENS_TABLE

USER_TOKENS_TABLE

Properties

$consumerKey

$consumerKey : string

Type

string — The unique ID of the tool consumer from whence the user is making requests to the LTI

$id

$id : string

Type

string — The unique ID (within the context of a particular Tool Consumer) of a particular user

$sql

$sql : \mysqli

Type

\mysqli — A MySQL connection

$token

$token : string|null

Type

string|null — This user's API access token (if acquired) or NULL if not yet acquired

$endpoint

$endpoint : string|null

Type

string|null — The URL of the API endpoint for which this user's API token is valid, NULL if no token

Methods

__construct()

__construct(string  $consumerKey, string  $userId, \mysqli  $mysqli) 

Create a new UserAPIToken to either register a new user in the USER_TOKENS_TABLE or look up an existing user.

Parameters

string $consumerKey

The unique ID of the Tool Consumer from whence the user is making requests to the LTI

string $userId

The unique ID of the user within that Tool Consumer

\mysqli $mysqli

An active MySQL database connection to update USER_TOKEN_TABLE

Throws

\UserAPIToken_Exception

CONSUMER_KEY_REQUIRED If no consumer key is provided

\UserAPIToken_Exception

USER_ID_REQUIRED If no user ID is provided

\UserAPIToken_Exception

MYSQLI_REQUIRED If no MySQL database connection is provided

\UserAPIToken_Excpetion

MYSQLI_ERROR If the user cannot be found or inserted in USER_TOKEN_TABLE

getToken()

getToken() : string|boolean

Returns

string|boolean —

The API access token for this user, or FALSE if no token has been acquired

setToken()

setToken(string  $token) : boolean

Stores a new API Token into USER_TOKEN_TABLE for this user

Parameters

string $token

A new API access token for this user

Throws

\UserAPIToken_Exception

TOKEN_REQUIRED If no token is provided

Returns

boolean —

Returns TRUE if the token is successfully stored in USER_TOKEN_TABLE, FALSE otherwise

getAPIEndpoint()

getAPIEndpoint() : string|boolean

Returns

string|boolean —

The URL of the API endpoint for which the user's API token is valid, or FALSE if no token has been acquired

setAPIEndpoint()

setAPIEndpoint(string  $endpoint) : boolean

Stores a new URL for the API endpoint for which the user's API access token is valid in USER_TOKEN_TABLE

Parameters

string $endpoint

The URL of the API endpoint

Throws

\UserAPITokenException

ENDPOINT_REQUIRED If no endpoint is provided

Returns

boolean —

TRUE if the URL of the API endpoint is stored in USER_TOKEN_TABLE, FALSE otherwise