gupalo / google-auth-bundle
Google Auth Bundle
Installs: 9 104
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.1
- ext-json: *
- doctrine/doctrine-bundle: ^2.5
- doctrine/orm: ^2.11|^3.0
- gupalo/browser-notifier: ^1.2
- gupalo/uidgenerator: ^1.1
- knpuniversity/oauth2-client-bundle: ^2.9
- league/oauth2-google: ^4.0
- symfony/form: ^5.4|^6.0
- symfony/security-core: ^5.4|^6.0
- symfony/translation: ^5.4|^6.0
- symfony/yaml: ^5.4|^6.0
- twig/twig: ^3.3
Requires (Dev)
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- dev-master
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.14
- 1.4.13
- 1.4.12
- 1.4.11
- 1.4.10
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.17
- 1.3.16
- 1.3.15
- 1.3.14
- 1.3.13
- 1.3.12
- 1.3.10
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-deprecation-fixes
- dev-user-identifier-depr-fix
- dev-support-condition-more-strict
This package is auto-updated.
Last update: 2024-12-09 14:09:30 UTC
README
Implementation of common authentication logic
Installation
Get Google App id and secret at https://console.developers.google.com/apis/credentials
Add env vars:
GOOGLE_AUTH_APP_ID
: from Google ConsoleGOOGLE_AUTH_APP_SECRET
: from Google ConsoleGOOGLE_AUTH_DOMAIN
: which domain is allowed to login; 'user.dev' to skip google auth and login all as ROLE_USER; "*" if all domains (only GSuite); overridegoogle_auth_domain: null
if you need to allow really all domains including "gmail.com"GOOGLE_AUTH_USERS
: which users should be autoactivated; empty if no usersGOOGLE_AUTH_ADMINS
: which users should be autoactivated as admins; empty if noneGOOGLE_AUTH_DEFAULT_APIKEY
: set if you want to autocreate "api@example.com" user with this key
And create config/packages/google_auth.yaml
parameters: env(GOOGLE_AUTH_APP_ID): something.apps.googleusercontent.com env(GOOGLE_AUTH_APP_SECRET): your_secret env(GOOGLE_AUTH_DOMAIN): "*" env(GOOGLE_AUTH_USERS): user1,user2 env(GOOGLE_AUTH_ADMINS): user1,user2 env(GOOGLE_AUTH_DEFAULT_APIKEY): '' google_auth_app_id: '%env(string:GOOGLE_AUTH_APP_ID)%' google_auth_app_secret: '%env(string:GOOGLE_AUTH_APP_SECRET)%' google_auth_domain: '%env(string:GOOGLE_AUTH_DOMAIN)%' google_auth_users: '%env(string:GOOGLE_AUTH_USERS)%' google_auth_admins: '%env(string:GOOGLE_AUTH_ADMINS)%' google_auth_default_apikey: '%env(string:GOOGLE_AUTH_DEFAULT_APIKEY)%'
Install
composer require gupalo/google-auth-bundle
- Check that GoogleAuthBundle and KnpUOAuth2ClientBundle are in
config/bundles.php
KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle::class => ['all' => true],
Gupalo\GoogleAuthBundle\GoogleAuthBundle::class => ['all' => true],
- Set
config/packages/security.yaml
security: encoders: Symfony\Component\Security\Core\User\User: algorithm: bcrypt providers: database_users: entity: { class: 'Gupalo\GoogleAuthBundle\Entity\User', property: username } role_hierarchy: ROLE_USER: [ROLE_API] firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false healthcheck: pattern: ^/healthcheck security: false api: pattern: ^/api/ anonymous: false stateless: true guard: authenticators: ['google_auth.security.google_authenticator'] entry_point: google_auth.security.google_authenticator provider: database_users main: pattern: ^/ logout: path: google_auth_security_logout target: homepage anonymous: true guard: authenticators: ['google_auth.security.google_authenticator'] entry_point: google_auth.security.google_authenticator provider: database_users remember_me: secret: "%secret%" lifetime: 31536000 # 365 days in seconds path: / domain: ~ # Defaults to the current domain from $_SERVER #always_remember_me: true access_control: - { path: ^/auth/, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/api/, roles: ROLE_API } - { path: ^/, roles: ROLE_USER }
- Enable GoogleAuthBundle routing. Add to
config/routes/google_auth.yaml
google_auth: resource: "@GoogleAuthBundle/Resources/config/routing/routing.yaml"
- Create
config/packages/google_auth.yaml
imports: - {resource: '@GoogleAuthBundle/Resources/config/services.yaml'}
- Update your database schema
Dev
Set to GOOGLE_AUTH_DOMAIN to one of the values below for dev environment
- user.dev - to login as [User::ROLE_USER]
- manager.dev - [User::ROLE_MANAGER]
- admin.dev - [User::ROLE_ADMIN]
- user-admin.dev - [User::ROLE_USER, User::ROLE_ADMIN]