Download the PHP package cidaas/oauth2-cidaas without Composer
On this page you can find all versions of the php package cidaas/oauth2-cidaas. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cidaas/oauth2-cidaas
More information about cidaas/oauth2-cidaas
Files in cidaas/oauth2-cidaas
Package oauth2-cidaas
Short Description Cidaas OAuth 2.0 and OpenID connect Client SDK
License MIT
Informations about the package oauth2-cidaas
About cidaas:
cidaas is a fast and secure Cloud Identity & Access Management solution that standardises what’s important and simplifies what’s complex.
Feature set includes:
- Single Sign On (SSO) based on OAuth 2.0, OpenID Connect, SAML 2.0
- Multi-Factor-Authentication with more than 14 authentication methods, including TOTP and FIDO2
- Passwordless Authentication
- Social Login (e.g. Facebook, Google, LinkedIn and more) as well as Enterprise Identity Provider (e.g. SAML or AD)
- Security in Machine-to-Machine (M2M) and IoT
Cidaas SDK for PHP
Requirements
Make sure you have installed all of the following prerequisites on your development machine:
- PHP version 7.4.0 or higher
- Download and install the composer
Installation
In order to use this sdk, you need to perform the following steps:
-
Add the cidaas repository to your composer.json configuration
- Install sdk dependency using composer
Integration
Prerequisites
Before you can start integrating this sdk, you need the following information:
- Base URL - URL of cidaas server
- Client id - issued by cidaas to identify your application
- Client secret - issued by cidaas to identify your application
- Redirect URI - URI to redirect to after successful login
In addition to this data, you should read the documentation at https://docs.cidaas.de with special attention to the integration chapters.
Please note that the web server running your php application needs direct access to the base url mentioned above. If this is not possible, think about using the javascript sdk for browser side integration.
Base communication provider
All communication is done using the php class Cidaas\OAuth2\Client\Provider\Cidaas
(called provider in the following chapters). In order to be
able to use this provider, you need to instantiate it with the prerequisites data mentioned above.
In addition to these required parameters, there are two optional constructor parameters:
- handler: to interfere with the http connections being performed
- debug: to enable debug mode
During construction, an http call is being performed to read base configuration data from the server.
Integration of hosted login page
In order to integrate a hosted login page, you might just implement a simple button, which itself calls the login method when clicked. By default pkce flow is disabled, to enable the pkce flow you must enable the flag $pkceEnabled by providing the value true in the function parameter.
After successful login, the browser is redirected to your selected redirectUri (see Prerequisites). Using the method loginCallback
enables you to retrieve the authorization code for retrieving access and refresh tokens.
Building your own login page
You can build your own login page and use a direct login mechanism. In order to access the login method, you need to retrieve a requestId first.
Retrieve tokens after login
Using the login result code, you can then get your access token and refresh token using the method getAccessToken
with GrantType AuthorizationCode
.
Building your own registration page
In order to build your own registration page, you can retrieve required fields using getRegistrationSetup
with requestId and locale.
Using the fields and another requestId, you can then register
a new customer.
Retrieve an access token by refresh token
In order to get a new access token by a given refresh token, you can also use the method getAccessToken
with GrantType RefreshToken
.
Logout
In order to perform a logout, you need an access token. Using this token, you can perform a logout.
Integration of hosted registration page
In order to integrate a hosted register page, you might just implement a simple button which itself calls the register method when clicked. The function accepts the below parameters
Param Name | Type | is optional | Default value | Description |
---|---|---|---|---|
scope | string | true | 'openid profile offline_access' | scope of the registered user |
queryParameters | associative array | true | [] | additional query params to add to the url. eg: ["local" => "en-US"] |
After successful registration, the browser is redirected to the login page for you to login with the registered details. The reirection may sometimes differ based on the configuration of the client.
Integration of social login page
To integrate social login redirection, you might just implement a simple button which itself calls the login method when clicked. In order to access the login method, you need to retrieve a requestId first. The function requires the provider name(e.g: google, facebbok) and the requestId as functional parameter and optinally more query params can be added to the request url.
This will redirect to the login page of the social provider. After successful login, the browser is redirected to your selected redirectUri (see Prerequisites).
Integration of social registration page
To integrate social registration redirection, you might just implement a simple button which itself calls the register method when clicked. In order to access the register method, you need to retrieve a requestId first. The function requires the provider name(e.g: google, facebbok) and the requestId as functional parameter and optionally more query params can be added to the request url.
This will redirect to the register page of the social provider. After successful registration, you can call the function loginWithSocial to start loging in to your cidaas client with the social provider.
Initiate multi factor authentication
To initiate multi factor authentication use the function intiateMFA. You need to retrieve a requestId first. Allowed types are mentioned in the list below
The api used in the function returns a response like shown below. You will require the exchange_id and sub from the response in order to complete the authentication process by calling the function authenticateMFA.
Authenticate multi factor
To authenticate multi factor you must first initiate the authentication process with the help of the function intiateMFA. You will be shared a passcode/verification code based on the type of authentication you prefer in the initiaition process. The types allowed for the authentication process are mentioned in the above section.
The api used in the function returns a response like shown below. After successful authentication you may proceed with your custom implementation. For any failure the attibute "success" in the response payload will have value false.
Initiate account verification
To initiate account verification use the function initiateAccountVerification. Account verification is done for newly created user account is not verified. If you are on cidaas v3, you must set the value v3 to the function parameter $version. The paramter $version is optional. Currently v2 and v3 version are supported. If not provided the default version v2 is considered to process the request further. A sample of the function parameter $params is shown below
-
Allowed values for verificationMedium
- Allowed values for verificationMedium
Once initiated successfully a passcode or a link will be sent to the preferred verificationMedium to verify your account
Verify account verificationMedium CODE
To complete account verification use the function verifyAccount. You will need the accvid which you will receive at the time of account verification initiation process.
The api used in the function returns a response like shown below. For failed verification the value of the attribute success will be false. After successful verification you may proceed with your custom implementation.
Perform progressive registration
Initiates progressive registration for missing required registration fields after an account is created in cidaas system. Below are the fields which can be updated in the process of progessive registration. All these fields need to passed in the function parameter $params
field name | type | |
---|---|---|
userStatus | string | |
user_status | string | |
user_status_reason | string | |
username | string | |
sub | string | |
given_name | string | |
family_name | string | |
middle_name | string | |
nickname | string | |
originalProviderUserId | string[] | |
string | ||
email_verified | boolean | |
mobile_number | string | |
mobile_number_verified | boolean | |
phone_number | string | |
phone_number_verified | boolean | |
profile | string | |
picture | string | |
website | string | |
gender | string | |
zoneinfo | string | |
locale | string | |
birthdate | Date | null |
address | IAddressEntity | |
customFields | any | |
identityCustomFields | any | |
password | string | |
provider | string | |
providerUserId | string | |
identityId | string | |
mfa_enabled | boolean | |
roles | string[] | |
userGroups | IUserGroupMap[] | |
groups | IUserGroupMap[] | |
rawJSON | string | |
trackId | string | |
need_reset_password | boolean |
The type IAddressEntity and IUserGroupMap contains the below fields
IAddressEntity
field name | type |
---|---|
formatted | string |
street_address | string |
locality | string |
region | string |
postal_code | string |
country | string |
IUserGroupMap
field name | type |
---|---|
sub | string |
groupId | string |
roles | string[] |
appendRole | boolean |
Get consent details
To get the consent details of a client use the function getConsentDetails. The function accepts 3 parameters consent_id, consent_version_id and sub.
Accept consent details
To accept consent by sub use the function acceptConsent. The function accepts a parameter of type array. Below are the fields that need to be passed in the array. A sample array is shown in the example below
field | type |
---|---|
client_id | string |
consent_id | string |
consent_version_id | string |
sub | string |
scopes | string[] |
url | string |
matcher | any |
field_key | string |
accepted_fields | string[] |
accepted_by | string |
skipped | boolean |
action_type | string |
action_id | string |
q | string |
revoked | boolean |
Get mfa list
Get the list of the mfa configured for an user use the function getMFAList. In order to get the list, you need to retrieve a requestId first. The function additionally accepts one of the below parameters
Initiate passwordless login
To initate passwordless login use the function initiatePasswordlessLogin. In order to initiate the process, you need to retrieve a requestId first. The function additionally accepts the below params
field | type |
---|---|
request_id | string |
type | string |
string | |
sub | string |
Verify passwordless login
To verify passwordless login after initiating the process use the function verifyPasswordlessLogin. The function additionally accepts the below params
field | type | description |
---|---|---|
type | string | preferred type of passwordless login. eg: email, totp |
exchange_id | string | exchange_id received in the response body while initiating the passwordless login |
pass_code | string | the passcode generated in the preferred type. eg: in case of email you will receive a passcode you the email provided |
requestId | string | use the same requestId that is being used while initiating the passwordless login |
Get user profile
To get user profile use the function getUserProfile. The function accepts below params
field | type | description |
---|---|---|
accessToken | string | The access token to authenticate the api. To get the accessToken you can use the function getAccessToken |
sub | string | sub is an optional parameter. If not provided the function returns the user details of sub in the access token. You can additionaly provide a sub to get the details of an specific sub |
Initiate reset password
To start a password reset process use the function initiateResetPassword. The function accepts the below params. The function returns a resetRequestId($rprq) which is required to validate the code(otp) sent to the email provided and later the same resetRequestId must be provided to complete the reset password process.
field | type | description |
---|---|---|
string | The email of the user account for which the password needs to be reset | |
requestId | string | In order to access the register method, you need to retrieve a requestId first |
Validate reset password code
To validate the code use the function handleResetPassword. The code will be sent to the email of the user when the password reset process is initiated. If you are on cidaas v3, you must set the value v3 to the function parameter version
field | type | description |
---|---|---|
code | string | The code(otp) received in mail when initiateResetPassword called |
resetRequestId | string | resetRequestId($rprq) recieved in the response when the password reset process is initiated |
version | string | cidaas version. Currently v2 and v3 version are supported. This is an optional parameter. If not provided the default version v2 is considered to process the request further |
Reset Password
To complete the password reset process use the function resetPassword. In cidaas version v2 the function returns a json response with success tru or false. If you are on cidaas v3, you must set the value v3 to the function parameter version
field | type | description |
---|---|---|
password | string | The new password |
confirmPassword | string | confirm the new password |
exchangeId | string | exchangeId recieved in the response of handleResetPassword function |
resetRequestId | string | resetRequestId($rprq) recieved in the response when the password reset process is initiated |
version | string | cidaas version. Currently v2 and v3 version are supported. This is an optional parameter. If not provided the default version v2 is considered to process the request further |
Unit testing
There are different ways of integrating php unit tests. Besides mocking the Cidaas
class, you may also add a mock handler to the constructor for low level tests.
This $mockHandler
is a default guzzle mock implementation created like this:
Please refer to https://docs.guzzlephp.org/en/stable/testing.html for further information.