playtini/auth-bundle

Simple Google Account Authentication Symfony Bundle

Installs: 162

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 4

Forks: 0

Open Issues: 0

Type:symfony-bundle

0.1.6 2018-07-06 12:40 UTC

This package is auto-updated.

Last update: 2024-12-05 19:32:49 UTC


README

Implementation of common authentication logic

Installation

  1. Use composer

Add parameters to app/config/parameters.yml.dist

parameters:
    google_app_id:     something.apps.googleusercontent.com
    google_app_secret: your_secret
    google_app_domain: yourdomain.com
    google_app_users: user1,user2

You may add parameters to env-map:

"google_app_id": "GOOGLE_APP_ID",
"google_app_secret": "GOOGLE_APP_SECRET",
"google_app_domain": "GOOGLE_APP_DOMAIN",
"google_app_users": "GOOGLE_APP_USERS",

Install

composer require playtini/auth-bundle
  1. Add PlaytiniAuthBundle and KnpUOAuth2ClientBundle to app/AppKernel.php
// app/AppKernel.php
new \KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle(),
new \Playtini\Bundle\AuthBundle\PlaytiniAuthBundle()
  1. Set app/config/security.yml
security:
    encoders:
        Symfony\Component\Security\Core\User\User:
            algorithm: bcrypt

    # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
    providers:
        database_users:
            entity: { class: 'Playtini\Bundle\AuthBundle\Entity\User', property: username }
        api_key_user_provider:
            id: playtini.auth.security.api_key_user_provider

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false
        api:
            pattern: ^/api/(?!key\.json)
            stateless: true
            simple_preauth:
                authenticator: playtini.auth.security.api_key_authenticator
            provider: api_key_user_provider
        main:
            pattern: ^/
            logout:       true
            anonymous:    true
            guard:
                authenticators:
                    - playtini.auth.security.google_authenticator
                entry_point: playtini.auth.security.google_authenticator
            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: ^/login/, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, roles: ROLE_USER }
  1. Enable AuthBundle routing. Add to app/config/routing.yml
playtini_auth:
    resource: "@PlaytiniAuthBundle/Resources/config/routing/routing.yml"
  1. Update your database schema