Code Monkey home page Code Monkey logo

ciricijwtclientbundle's Introduction

CiriciJWTClientBundle

Build status Code coverage License Latest stable version Total downloads Code climate

This Bundle is used to login against a JWT server or to check the validity of a JWT Token

It has been based on these instructions.

WARNING! This bundle is Work In Progress and is not ready for production yet

Installation

composer require ciricihq/jwt-client-bundle:dev-master

Then add to AppKernel.php

        $bundles = [
            ...
            new Cirici\JWTClientBundle\CiriciJWTClientBundle(),
            ...
        ];

Configuration

If you are planning to use the bundle as a Authentication service against a JWT server, you should load the external token authenticator adding this to your config.yml

cirici_jwt_client:
    use_external_jwt_api: true
    external_api: "@eight_points_guzzle.client.api_jwt"
    jwt_token_path: /jwt/token # Endpoint where the token POST request will be done

And you must define the api using Guzzle configuration

guzzle:
    clients:
        api_jwt:
            base_url: %api_jwt_base_url%

Configure security for login form against external JWT server

In order to make this bundle work you should define your security.yml like this

# To get started with security, check out the documentation:
security:
    providers:
        token:
            id: project.token.user_provider

    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            pattern: ^/
            provider: token
            anonymous: true
            simple_form:
                authenticator: project.token.external_authenticator
                check_path: login_check
                login_path: login
                # user_referer: true
                failure_path: login
            logout:
                path: /logout
                target: login
            remember_me:
                secret: '%secret%'
                lifetime: 86400
                path: /

    access_control:
        - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/registration, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, role: ROLE_ADMIN }

In routes.yml you has to add a login path as those lines for the login fails redirect and add the bundle routes import as well:

jwt_client:
    resource: '@CiriciJWTClientBundle/Resources/config/routing.yml'
    prefix: /

login:
    path: /login

Setting up custom User class for incoming requests

If you want to map the incoming token calls with a custom User class instead of ApiUser you should implement Cirici\JWTClientBundle\Security\ApiUserInterface in your custom User class. Then configure your custom User class in config.yml:

cirici_jwt_client:
    api_user_class: '\AppBundle\Entity\User'

Configure to validate incoming Authentication bearer

In your security.yml firewall you has to add the next lines:

security:
    providers:
        token:
            id: project.token.user_provider

    firewalls:
        api:
            pattern:   ^/api/user
            stateless: true
            guard:
                provider: token
                authenticators:
                    - project.token.authenticator

Extending login template

If you want to modify the default login template you should create the next folders

mkdir -P app/Resources/CiriciJWTClientBundle/views/Security

And then copy the file login.html.twig from the bundle to the folder created above.

Now your app will load the login template just copied and you can modify it without altering the bundle one. :)

ciricijwtclientbundle's People

Contributors

elboletaire avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

ciricijwtclientbundle's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.