ac/login-convenience-bundle
Symfony bundle that streamlines JSON API authentication with OpenID via FpOpenIdBundle. Includes a base User class, JSON login/logout endpoints, auth-header session storage (no cookies), reload-less OpenID flow support, trusted providers, and dummy login mode.
Installation
composer require ac/login-convenience-bundle
Ensure FpOpenIdBundle is also installed (dependency).
Configure Kernel
Add to AppKernel.php:
new ACLoginConvenienceBundle(),
new Fp\OpenIdBundle\FpOpenIdBundle(),
Security Configuration
Replace security.yml with:
ac_login_convenience:
secured_paths:
- /api/protected-route
Routing
Add to routing.yml:
ac_login_convenience:
resource: "."
type: "ac_login_convenience_routes"
Create a User
php app/console ac:login-convenience:create-user username email openid_url
Test Login
Use the /login endpoint with OpenID credentials or the dummy mode for development.
API Authentication Flow
/login with OpenID provider (e.g., Google, GitHub).Authorization header).Authorization header for session persistence./login?openid=<provider_url>.session_token and user_data:
{
"status": "success",
"session_token": "abc123...",
"user": { "id": 1, "username": "user1" }
}
security.yml under secured_paths.ac_login_convenience:
secured_paths:
- /api/v1/data
Authorization header for session tokens./logout (returns JSON response).config.yml to use Authorization header:
framework:
session:
storage_id: ac_login_convenience.session.storage.auth_header
php app/console ac:login-convenience:create-user john doe@example.com https://google.com
ac_login_convenience:add-openid command or manually insert into openid_identity table.Service Provider Setup
Register the bundle in config/app.php under providers:
AmericanCouncils\LoginConvenienceBundle\ACLoginConvenienceBundle::class,
Fp\OpenIdBundle\FpOpenIdBundle::class,
Route Service Provider
Override mapApiRoutes in RouteServiceProvider to include bundle routes:
$this->router->group(['prefix' => 'api'], function () {
require base_path('routes/api.php');
$this->loadRoutesFrom(__DIR__.'/../routes/ac_login_convenience.php');
});
Middleware for API
Use Laravel’s auth:api middleware for token validation (customize if needed):
protected function authenticateRequests()
{
$this->middleware('auth:api', ['except' => [...]]);
}
Custom User Model
Extend the bundle’s AbstractUser:
use AmericanCouncils\LoginConvenienceBundle\Model\User as BaseUser;
class User extends BaseUser
{
// Add custom fields/methods
}
Register in config/auth.php:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
],
OpenID Provider Configuration
trusted_providers config.config.yml:
ac_login_convenience:
trusted_providers:
- google
- github
- my-custom-provider
Session Storage Quirks
auth_header storage, ensure the Authorization header is consistently formatted:
Authorization: Bearer <session_token>
php app/console debug:container ac_login_convenience.session.storage.auth_header
Dummy Login Mode
ac_login_convenience:
dummy_login: false
CSRF Protection
$this->middleware('csrf', ['except' => ['store']]);
Database Migrations
php artisan migrate
User or OpenIdIdentity tables.Login Failures
var/logs/dev.log for provider errors.openid_identity table has valid entries for users.Token Validation Errors
Authorization header is included in requests.curl -H "Authorization: Bearer <token>" http://yourapi.com/protected
Route Conflicts
/_ac_login_convenience. Avoid naming conflicts.Custom OpenID Providers
Extend the Fp\OpenIdBundle\Provider\ProviderInterface and register in config.yml:
ac_login_convenience:
custom_providers:
my_provider:
class: App\CustomOpenIdProvider
args: [@service_id]
Event Listeners
Listen to bundle events (e.g., ac.login.success) for custom logic:
use AmericanCouncils\LoginConvenienceBundle\Event\LoginEvent;
$dispatcher->addListener('ac.login.success', function (LoginEvent $event) {
// Custom post-login logic
});
Override Templates
Customize OpenID login templates in Resources/views/OpenId/:
association.html.twiglogin.html.twigAPI Response Modification
Extend the ACLoginConvenienceBundle\Controller\SecurityController to override JSON responses:
class CustomSecurityController extends SecurityController
{
public function loginAction()
{
$response = parent::loginAction();
$response->setData(['custom_field' => 'value']);
return $response;
}
}
Register the override in services.yml:
services:
ac_login_convenience.controller.security:
class: AppBundle\Controller\CustomSecurityController
arguments: [...]
How can I help you explore Laravel packages today?