PHP code example of cidaas / oauth2-cidaas
1. Go to this page and download the library: Download cidaas/oauth2-cidaas library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cidaas / oauth2-cidaas example snippets
$provider = new Cidaas('https://yourcidaasinstance.cidaas.de', 'client id', 'client secret', 'https://yourwebsite/redirectAfterLogin');
$provider->loginWithBrowser();
$parameters = $provider->loginCallback();
if (array_key_exists('code', $parameters)) {
$loginResultCode = $parameters['code'];
}
try {
$loginResult = $provider->getRequestId('openid identities profile offline_access')->then(function ($requestId) {
return $provider->loginWithCredentials($username, 'email', $password, $requestId);
})->wait();
$loginResultCode = $loginResult['data']['code'];
} catch (ClientException $exception) {
$errorBody = json_decode($exception->getResponse()->getBody(), true);
$passwordErrorMessage = $errorBody['error']['error_description'];
}
$accessTokenResponse = $provider->getAccessToken(GrantType::AuthorizationCode, $loginResultCode)->wait();
$accessToken = $accessTokenResponse['access_token'];
$refreshToken = $accessTokenResponse['refresh_token'];
$registrationResponse = $provider->getRequestId()->then(function ($requestId) {
return $provider->getRegistrationSetup($requestId, $locale);
})->wait();
$registrationFields = $registrationResponse['data'];
try {
$registrationResponse = $provider->getRequestId()->then(function ($requestId) {
return $provider->register($fields, $requestId);
})->wait();
} catch (ClientException $exception) {
$errorMessage = json_decode($exception->getResponse()->getBody())['error']['error'];
}
$accessToken = $provider->getAccessToken(GrantType::RefreshToken, '', $refreshToken)->then(function ($response) {
return $response['access_token'];
})->wait();
$provider->logout($accessToken);
$provider->registerWithBrowser();
$provider->getRequestId('openid identities profile offline_access')->then(function ($requestId) {
$provider->loginWithSocial('google', $requestId);
})
$provider->getRequestId('openid identities profile offline_access')->then(function ($requestId) {
$provider->registerWithSocial('google', $requestId);
})
$resp = $provider->getRequestId('openid identities profile offline_access')->then(function ($requestId) {
$params = [
"email" => '[email protected] '
"request_id" => $requestId,
"usage_type" => "MULTIFACTOR_AUTHENTICATION"
]
$resp = $provider->intiateMFA('EMAIL', $params)->wait();
})
$resp = $provider->authenticateMFA('a64782cd-d136-4fc3-a879-3afb4feb7453', '3e851ef6-d6f4-41c3-8ff0-8277279c0fbd', '123456', 'EMAIL')->wait();
$params = [
"response_type": "token",
"verificationMedium": "email",
"processingType": "code",
"client_id": "103a3f9c-1a2d-4e47-940k-bad7f19d9604",
"redirect_uri": "https://test.cidaas.com/user-profile/editprofile",
"email": "[email protected] "
]
$provider->initiateAccountVerification($params)->wait();
$resp = $provider->verifyAccount("103a3f9c-1a2d-4e47-940k-bad7f19d9604", "123456")->wait();
$params = [
"given_name": "Firstname",
"username": "test_username",
"family_name": "Lastname",
"mobile_number": "7865637869"
]
$resp = $provider->progressiveRegistration("103a3f9c-1a2d-4e47-940k-bad7f19d9604", "203a3f9c-1a2d-4e47-940k-bad7f19d9604", $params)->wait();
$resp = $provider->getConsentDetails("103a3f9c-1a2d-4e47-940k-bad7f19d9604", "1", "503a3f9c-1a2d-4e47-940k-bad7f19d960")->wait();
$params = [
"client_id": "1234567",
"consent_id": "1234567",
"consent_version_id": "1",
"sub": "1234567",
"url" : "https://cidaas.de/accept-consent"
]
$resp = $provider->acceptConsent($params)->wait();
$provider->getRequestId('openid identities profile offline_access')->then(function ($requestId) {
$resp = $provider->getMFAList($requestId, "[email protected] ")->wait();
})
$provider->getRequestId('openid identities profile offline_access')->then(function ($requestId) {
$resp = $provider->initiatePasswordlessLogin($requestId, "email", '[email protected] ', '1234567')->wait();
})
$provider->getRequestId('openid identities profile offline_access')->then(function ($requestId) {
$resp1 = $provider->initiatePasswordlessLogin($requestId, "email", '[email protected] ', '1234567')->wait();
$resp2 = $provider->verifyPasswordlessLogin("email",$resp1->exchange_id, '123456', $requestId)->wait();
})
$resp1 = $provider->getUserProfile($accessToken, $sub)->wait();
$provider->getRequestId('openid identities profile offline_access')->then(function ($requestId) {
$res = $provider->initiateResetPassword($email, $requestId)->wait();
})
$resp = $provider->handleResetPassword($code, $resetRequestId)->wait();
$resp = $provider->resetPassword($password, $confirmPassword, $exchangeId, $resetRequestId)->wait();
$cidaas = new Cidaas('https://yourcidaasinstance.cidaas.de', 'client id', 'client secret', 'https://yourwebsite/redirectAfterLogin', $mockHandler);
$mock = new MockHandler([new Response(200, [], $mockedResponse)]);
$mockHandler = HandlerStack::create($this->mock);