NamelessOAuth
extends Instanceable
in package
OAuth utility class.
Tags
Table of Contents
Properties
- $_db : DB
- $_instances : array<class-string, static>
- Stores instances of classes with their class name as key.
- $_provider_instances : array<string|int, mixed>
- $_providers : array<string|int, mixed>
Methods
- __construct() : mixed
- getCredentials() : array<string|int, mixed>
- Get the client ID and client secret for a specific provider.
- getInstance() : static
- Get or make an instance of the class this was called on.
- getProvider() : null|array<string|int, mixed>
- Get or create an instance of a specific provider.
- getProviderInstance() : AbstractProvider
- Get or create an instance of a specific provider.
- getProviders() : array<string|int, mixed>
- Get an array of all registered provider names and their data.
- getProvidersAvailable() : array<string|int, mixed>
- Get an array of provider names and their URL & icon.
- getUserIdName() : string
- Get the array key for a specific providers client ID.
- hasVerifiedEmail() : bool
- Determine if the email returned from a provider is verified on their end.
- isEnabled() : bool
- Determine if a provider is enabled (different from setup!).
- isSetup() : bool
- Determine if a provider is setup.
- registerProvider() : void
- Add an OAuth provider to the system.
- setCredentials() : void
- Update the client ID and client secret for a specific provider.
- setEnabled() : void
- Set a provider as enabled or disabled (`1` or `0` respectively).
- formatCss() : string
- Format an array of CSS rules into a string, appending `!important` to each rule.
Properties
$_db
private
DB
$_db
$_instances
Stores instances of classes with their class name as key.
private
static array<class-string, static>
$_instances
= []
$_provider_instances
private
array<string|int, mixed>
$_provider_instances
= []
$_providers
private
array<string|int, mixed>
$_providers
= []
Methods
__construct()
public
__construct() : mixed
getCredentials()
Get the client ID and client secret for a specific provider.
public
getCredentials(string $provider) : array<string|int, mixed>
Parameters
- $provider : string
-
The provider name
Return values
array<string|int, mixed> —The configured credentials for this provider
getInstance()
Get or make an instance of the class this was called on.
public
final static getInstance() : static
Return values
static —Instance of the class this was called on.
getProvider()
Get or create an instance of a specific provider.
public
getProvider(string $provider) : null|array<string|int, mixed>
Parameters
- $provider : string
-
The provider name
Return values
null|array<string|int, mixed> —An array of registered OAuth provider.
getProviderInstance()
Get or create an instance of a specific provider.
public
getProviderInstance(string $provider) : AbstractProvider
Parameters
- $provider : string
-
The provider name
Return values
AbstractProvider —The provider instance
getProviders()
Get an array of all registered provider names and their data.
public
getProviders() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of all registered OAuth providers.
getProvidersAvailable()
Get an array of provider names and their URL & icon.
public
getProvidersAvailable() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array of provider names and their instances
getUserIdName()
Get the array key for a specific providers client ID.
public
getUserIdName(string $provider) : string
Discord uses id
and Google uses sub
, so we have to be able to differentiate.
Parameters
- $provider : string
-
The provider name
Return values
string —The array key for the provider's client ID
hasVerifiedEmail()
Determine if the email returned from a provider is verified on their end.
public
hasVerifiedEmail(string $provider, array<string|int, mixed> $provider_user) : bool
Used during registration to auto verify emails (if they enter the same one as the provider returned).
Parameters
- $provider : string
-
The provider name
- $provider_user : array<string|int, mixed>
-
The provider user data (aka resource owner)
Return values
bool —Whether the email returned from the provider is verified or not
isEnabled()
Determine if a provider is enabled (different from setup!).
public
isEnabled(string $provider) : bool
Parameters
- $provider : string
-
The provider name
Return values
bool —If the provider is enabled
isSetup()
Determine if a provider is setup.
public
isSetup(string $provider) : bool
A provider is considered setup if it has a client ID and a client secret set.
Parameters
- $provider : string
-
The provider name
Return values
bool —If the provider is setup
registerProvider()
Add an OAuth provider to the system.
public
registerProvider(string $name, string $module, array<string|int, mixed> $data[, array<string|int, mixed> $extra_options = [] ]) : void
Parameters
- $name : string
-
The name of the provider (Discord, Google, etc).
- $module : string
-
Name of the module which registered this provider.
- $data : array<string|int, mixed>
-
Metadata about the provider: class, user_id_name, scope_id_name, icon
- $extra_options : array<string|int, mixed> = []
-
Extra options to pass to the provider constructor. Example: keycloak needs some specific options
setCredentials()
Update the client ID and client secret for a specific provider.
public
setCredentials(string $provider, string $client_id, string $client_secret) : void
Parameters
- $provider : string
-
The provider name
- $client_id : string
-
The new client ID
- $client_secret : string
-
The new client secret
setEnabled()
Set a provider as enabled or disabled (`1` or `0` respectively).
public
setEnabled(string $provider, int $enabled) : void
Parameters
- $provider : string
-
The provider name
- $enabled : int
-
Whether to enable or disable the provider
formatCss()
Format an array of CSS rules into a string, appending `!important` to each rule.
private
formatCss(array<string|int, mixed> $css) : string
Parameters
- $css : array<string|int, mixed>
-
CSS rule => value array
Return values
string —The CSS string