Giter Site home page Giter Site logo

symfony-api-swagger-jwt's Introduction

Symfony API with Swagger Documentation and JWT Authentication and Authorization

Requirements

Set-up

  • Clone this repo.
  • Run composer install.
    • if you're using the Vagrant env (linked above) then composer install will run during the ansible provisioning
    • if you're using the Docker env (linked above) then composer install will run during docker-compose up
      • you can tail the logs using docker logs -f {name_of_docker_container_running_composer}

Swagger Docs

  • The Swagger docs for the API are secured with Basic Http Authentication (swagger - swagger) and should be visible at http://{your_local_host}/app_dev.php/api#.

  • To generate the docs for "production" (i.e., http://{your_local_host}/api#) run php app/console assetic:dump --env=prod --no-debug.

  • To change the password for the docs run the following and then add the Encoded password to parameters.yml.dist and run composer install:  

      php app/console security:encode-password {your_swagger_password}
    

JWT Set-Up

  • JWT set-up uses the approach described in this post - http://kolabdigital.com/lab-time/symfony-json-web-tokens-authentication-guard.

  • You'll need to generate the keys as described in the link.  

      mkdir -p app/var/jwt
      openssl genrsa -out app/var/jwt/private.pem -aes256 4096
      openssl rsa -pubout -in app/var/jwt/private.pem -out app/var/jwt/public.pem
    
  • Omit -aes256 to generate keys without using a passphrase.
     

      openssl genrsa -out app/var/jwt/private.pem 4096
      openssl rsa -pubout -in app/var/jwt/private.pem -out app/var/jwt/public.pem
    

Log-in

  • You can set up an admin user by running the following:
     

      php app/console doctrine:mongodb:fixtures:load 
    
  • You can then login by calling POST /login with the following request body:  

      {
          "email": "[email protected]",
          "password": "admin"
      }
    

Running Tests

To run the test suite execute bin/phpunit -c app/.

symfony-api-swagger-jwt's People

Contributors

bendbennett avatar

Watchers

James Cloos avatar Lê Công Tính avatar

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.