AuthRocket
AuthRocket provides Auth as a Service, making it quick and easy to add signups, logins, social auth, a full user management UI, and much more to your app., (*1)
The authrocket
PHP library covers all of our Core API. It also covers select portions of the Configuration API., (*2)
Installation
The library is designed to be installed using composer
. It should also be usable using any other method typically supported by composer-compatible packages., (*3)
For installation, run:, (*4)
composer require authrocket/authrocket
# alternate:
php composer.phar require authrocket/authrocket
Or, add "authrocket/authrocket": "^2"
to the require
section of your composer.json and run composer install
., (*5)
You can also download authrocket.phar
, a .zip, or a .tar.gz of the latest release directly from GitHub: https://github.com/authrocket/authrocket-php/releases/latest, (*6)
Client Basics
Using environment variables
If you are using environment variables to manage external services like AuthRocket, then it's very easy to initialize the AuthRocket client:, (*7)
$client = \AuthRocket\AuthRocket::autoConfigure();
Ensure these environment variables are set:, (*8)
# If only validating tokens
LOGINROCKET_URL = https://SAMPLE.e2.loginrocket.com/
# If only validating tokens and default JWT key type has been changed to HS256
LOGINROCKET_URL = https://SAMPLE.e2.loginrocket.com/
AUTHROCKET_JWT_KEY = SAMPLE
# To use the AuthRocket API
AUTHROCKET_API_KEY = ks_SAMPLE
AUTHROCKET_URL = https://api-e2.authrocket.com/v2
AUTHROCKET_REALM = rl_SAMPLE # optional, but recommended (see below)
# plus LOGINROCKET_URL and/or AUTHROCKET_JWT_KEY if also validating tokens
AUTHROCKET_API_KEY = ks_SAMPLE
Your AuthRocket API key. Required to use the API (but not if only performing JWT verification of login tokens)., (*9)
AUTHROCKET_JWT_KEY = SAMPLE
Used to perform JWT signing verification of login tokens. Not required if validating all tokens using the API instead. Also not required if LOGINROCKET_URL is set and RS256 keys are being used, as public keys will be auto-retrieved. This is a realm-specific value, so like AUTHROCKET_REALM
, set it directly if using multiple realms (see below)., (*10)
AUTHROCKET_REALM = rl_SAMPLE
Sets an application-wide default realm ID. If you're using a single realm, this is definitely easiest. Certain multi-tenant apps might use multiple realms. In this case, don't set this globally, but directly when constructing the client (see below)., (*11)
AUTHROCKET_URL = https://api-e2.authrocket.com/v2
The URL of the AuthRocket API server. This may vary depending on which cluster your service is provisioned on., (*12)
LOGINROCKET_URL = https://SAMPLE.e2.loginrocket.com/
The LoginRocket URL for your Connected App. Used for auto-retrieval of RS256 JWT keys (if AUTHROCKET_JWT_KEY is not set). If your app uses multiple realms, you may need to set this directly instead (see below). If you're using a custom domain, this will be that domain and will not contain 'loginrocket.com'., (*13)
If you are using multiple realms, we recommend building a new client for each realm, directly setting realm
, jwtKey
, and/or loginrocketUrl
:, (*14)
$client = \AuthRocket\AuthRocket::autoConfigure([
'realm' => 'rl_SAMPLE',
'jwtKey' => 'SAMPLE',
'loginrocketUrl' => 'https://SAMPLE.e2.loginrocket.com/'
]);
Similarly, if changing locales between requests, build a new client for each:, (*15)
$client = \AuthRocket\AuthRocket::autoConfigure([
'locale' => 'es'
]);
Direct configuration
It's also possible to configure the AuthRocket client instance directly:, (*16)
$client = new \AuthRocket\AuthRocket([
'apiKey' => 'ks_SAMPLE',
'url' => 'https://api-e2.authrocket.com/v2',
'realm' => 'rl_SAMPLE',
'jwtKey' => 'SAMPLE',
'loginrocketUrl' => 'https://SAMPLE.e2.loginrocket.com/',
'locale' => 'en'
]);
Usage
Documentation is provided on our site:, (*17)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
)
- Commit your changes (
git commit -am 'Add some feature'
)
- Push to the branch (
git push origin my-new-feature
)
- Create new Pull Request
License
MIT, (*18)