class User extends Base (View source)

User management client for the rokka.io service.

Constants

DEFAULT_API_BASE_URL

protected DEFAULT_API_VERSION

protected API_KEY_HEADER

protected API_AUTHORIZATION_HEADER

protected API_VERSION_HEADER

USERS_RESOURCE

USER_RESOURCE

USER_API_KEYS_RESOURCE

ORGANIZATION_RESOURCE

ORGANIZATION_OPTION_PROTECT_DYNAMIC_STACK

Properties

protected ClientInterface $client

Client to access Rokka.

from  Base
protected string|null $defaultOrganization

Default organization.

from  Base

Methods

__construct(ClientInterface $client, string|null $defaultOrganization, string|null $apiKey, string|null $apiToken = null)

Constructor.

void
setCredentials(string|null $key)

Set the credentials.

from  Base
void
setToken(string|null $token)

Set the API Token.

from  Base
string|null
getToken()

Get the API Token.

from  Base
array|null
getTokenPayload(string|null $token = null)

Get the API Token Payload (unverified).

from  Base
int
getTokenIsValidFor(string|null $token = null)

Returns for how many seconds a token is valid for.

from  Base
ResponseInterface
call(string $method, string $path, array $options = [], bool $needsCredentials = true, array $credentials = [])

Call the API rokka endpoint.

from  Base
string
getOrganizationName(string|null $organization = null)

Return the organization or the default if empty.

from  Base
array|null
getUnvalidatedPayload(string $token)

Gets the payload of an API JWT Token (not validated against the signature).

from  Base
createUser(string $email)

Create a user.

string
getCurrentUserId()

Get current userID.

addUserApiKey(string $comment = null)

Add an Api Key to the current user.

getCurrentUserApiKey()

Gets info about the currently used Api Key.

bool
deleteUserApiKey(string $id)

Deletes an Api Key for the current user.

getCurrentUser()

Get current user.

getNewToken(string|null $apiKey = null, array $parameters = [])

Gets a new API JWT Token with an $apiKey.

createOrganization(string $name, string $billingMail, string $displayName = '')

Create an organization.

setOrganizationOption(string $organization, string $name, string $value)

Create an organization.

getOrganization(string $organization = '')

Return an organization.

createMembership(string $userId, string|array $roles = [Membership::ROLE_READ], string $organization = '')

Create a membership.

createUserAndMembership(string|array $roles = [Membership::ROLE_READ], string $organization = '')

Create a user and membership associated to this organization.

getMembership(string $userId, string $organization = '')

Get the membership metadata for the given organization and user's ID.

bool
deleteMembership(string $userId, string $organization = '')

Deletes a membership for the given organization and user's ID.

listMemberships(string $organization = '')

List the membership metadata for the given organization.

Details

__construct(ClientInterface $client, string|null $defaultOrganization, string|null $apiKey, string|null $apiToken = null)

Constructor.

Parameters

ClientInterface $client

Client instance

string|null $defaultOrganization
string|null $apiKey

API key

string|null $apiToken

API Token

void setCredentials(string|null $key)

Set the credentials.

Parameters

string|null $key

API key

Return Value

void

void setToken(string|null $token)

Since: 1.17.0

Set the API Token.

Parameters

string|null $token

API token

Return Value

void

string|null getToken()

Since: 1.17.0

Get the API Token.

Return Value

string|null

array|null getTokenPayload(string|null $token = null)

Since: 1.17.0

Get the API Token Payload (unverified).

Parameters

string|null $token

Return Value

array|null

int getTokenIsValidFor(string|null $token = null)

Since: 1.17.0

Returns for how many seconds a token is valid for.

Doesn't check for other validity (like ip restrictions)

Returns -1 if there's no token

Parameters

string|null $token

Return Value

int

protected ResponseInterface call(string $method, string $path, array $options = [], bool $needsCredentials = true, array $credentials = [])

Call the API rokka endpoint.

Parameters

string $method

HTTP method to use

string $path

Path on the API

array $options

Request options

bool $needsCredentials

True if credentials are needed

array $credentials

Credentials to be used, useful for overwriting api-key

Return Value

ResponseInterface

Exceptions

GuzzleException

protected string getOrganizationName(string|null $organization = null)

Return the organization or the default if empty.

Parameters

string|null $organization Organization

Return Value

string

Exceptions

RuntimeException

protected array|null getUnvalidatedPayload(string $token)

Gets the payload of an API JWT Token (not validated against the signature).

Parameters

string $token

Return Value

array|null

User createUser(string $email)

Create a user.

Parameters

string $email Email

Return Value

User

Exceptions

GuzzleException
RuntimeException

string getCurrentUserId()

Since: 1.7.0

Get current userID.

Return Value

string

Exceptions

GuzzleException
RuntimeException

UserApiKey addUserApiKey(string $comment = null)

Since: 1.16.0

Add an Api Key to the current user.

Parameters

string $comment

Optional comment

Return Value

UserApiKey

Exceptions

GuzzleException

UserApiKey getCurrentUserApiKey()

Since: 1.16.0

Gets info about the currently used Api Key.

Return Value

UserApiKey

Exceptions

GuzzleException

bool deleteUserApiKey(string $id)

Since: 1.16.0

Deletes an Api Key for the current user.

Parameters

string $id

Return Value

bool

returns false, if key didn't exist, true if operation succeeded

Exceptions

GuzzleException

User getCurrentUser()

Since: 1.16.0

Get current user.

Return Value

User

Exceptions

GuzzleException
RuntimeException

UserApiToken getNewToken(string|null $apiKey = null, array $parameters = [])

Since: 1.17.0

Gets a new API JWT Token with an $apiKey.

Parameters

string|null $apiKey

The api key, if different from the base one

array $parameters

The /user/apikeys/token query parameters

Return Value

UserApiToken

Exceptions

GuzzleException

See also

https://rokka.io/documentation/guides/authentication.html#using-rokka-with-a-jwt-token
https://api.rokka.io/doc/#/admin/getUserToken

Organization createOrganization(string $name, string $billingMail, string $displayName = '')

Create an organization.

Parameters

string $name

Organization name

string $billingMail

Billing mail

string $displayName

Optional display name

Return Value

Organization

Exceptions

GuzzleException
RuntimeException

Organization setOrganizationOption(string $organization, string $name, string $value)

Since: 1.13.0

Create an organization.

Parameters

string $organization

Organization name

string $name

Option name

string $value

Option Value

Return Value

Organization

Exceptions

GuzzleException
RuntimeException

Organization getOrganization(string $organization = '')

Since: 1.7.0

Return an organization.

Parameters

string $organization

Organization name

Return Value

Organization

Exceptions

GuzzleException
RuntimeException

Membership createMembership(string $userId, string|array $roles = [Membership::ROLE_READ], string $organization = '')

Since: 1.7.0

Create a membership.

Parameters

string $userId

User ID

string|array $roles

Role to add

string $organization Organization

Return Value

Membership

Exceptions

GuzzleException
RuntimeException

Membership createUserAndMembership(string|array $roles = [Membership::ROLE_READ], string $organization = '')

Since: 1.7.0

Create a user and membership associated to this organization.

Parameters

string|array $roles

Role to add

string $organization Organization

Return Value

Membership

Exceptions

GuzzleException
RuntimeException

Membership getMembership(string $userId, string $organization = '')

Since: 1.7.0

Get the membership metadata for the given organization and user's ID.

Parameters

string $userId

User ID

string $organization Organization

Return Value

Membership

Exceptions

GuzzleException
RuntimeException

bool deleteMembership(string $userId, string $organization = '')

Since: 1.7.0

Deletes a membership for the given organization and user's ID.

Parameters

string $userId

User ID

string $organization Organization

Return Value

bool

Exceptions

GuzzleException
RuntimeException

Membership[] listMemberships(string $organization = '')

Since: 1.7.0

List the membership metadata for the given organization.

Parameters

string $organization Organization

Return Value

Membership[]

Exceptions

GuzzleException
RuntimeException