1. Go to this page and download the library: Download holadev/oauth2-loginradius 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/ */
holadev / oauth2-loginradius example snippets
class User implements UserInterface, \Serializable , OauthUserInterface
class UserRepository extends ServiceEntityRepository implements UserLoaderInterface
{
public function loadUserByUsername($username)
{
return $this->findOneBy(['email' => $username]);
}
}
class LoginRadiusController extends Controller
{
/**
* Link to this controller to start the "connect" process
*
* @Route("/connect/loginradius", name="connect_loginradius_start")
*/
public function connectAction(ClientRegistry $clientRegistry, Request $request)
{
return $clientRegistry
->getClient('loginradius_oauth') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([
'profile','&action=login®Source=cabecera&new=1' // the scopes you want to access
])
;
}
/**
* @Route("/connect/loginradius/check", name="connect_loginradius_check")
*/
public function connectCheckAction(Request $request, ClientRegistry $clientRegistry)
{
$client = $clientRegistry->getClient('loginradius_oauth');
try {
$user = $client->fetchUser();
$accessToken = $client->getAccessToken();
//Login the user saving the accesstoken and redirect to the original url
//$this->userService->userLogin($user,$accessToken, $request);
return new RedirectResponse(
'/myoriginalurl',
// might be the site, where users choose their oauth provider
Response::HTTP_TEMPORARY_REDIRECT
);
// ...
} catch (IdentityProviderException $e) {
// something went wrong!
// probably you should return the reason to the user
var_dump($e->getMessage()); die;
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.