GithubHelp home page GithubHelp logo

agora-api's Introduction

agora-api

Disclaimer Ce site a été réalisé à des fins pédagogiques dans le cadre du cursus Bachelor de l’école HETIC. Les contenus présentés n'ont pas fait l'objet d'une demande de droit d'utilisation. Ce site ne sera en aucun cas exploité à des fins commerciales.


Swagger documentation

Visit the documentation at route: /swagger/index.html.


Installing the project

After cloning the project, go to the root of the project and create a .env.local file:

touch .env.local

In .env.local add these lines and make changes according to your configuration:

APP_ENV=dev
DATABASE_URL=mysql://db_user:[email protected]:3306/agoraDb?serverVersion=5.7
CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$

Basic commands

Then, install dependencies:

Normal

composer install

Makefile

make install

Create the Database:

Normal

./bin/console doctrine:database:create

Makefile

make db-create

Execute the last migration:

Normal

./bin/console doctrine:migration:migrate

Makefile

make db-migration

Populate database with fixtures:

Normal

./bin/console doctrine:fixtures:load

Makefile

make db-fixture

Launch the server:

Normal

symfony server:start

Makefile way

make start

Stop the server:

make stop

Setup JWT Token

First create the JWT Folder in config folder:

mkdir -p config/jwt

Then, generate your .pem keys according to your JWT_PASSPHRASE located in .env, ie, when you will have to enter the passphrase enter the same value as the JWT_PASSPHRASE:

openssl genrsa -out config/jwt/private.pem -aes256 4096

Same for this command:

openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem

Now, if you try to login as an existing user like so:

httpie

http POST localhost:8000/api/login_check [email protected] password=test

CURL

curl -X POST -H "Content-Type: application/json" localhost:8000/api/login_check -d '{"username": "[email protected]", "password": "test"}'

You will retrieve the JWT Token:

{
    "token": "eyJ0eXAi..."
}

With this JWT Token, you can now make request on routes /api of the application. You need to put the token in your Headers every time you want to make a request.

httpie-jwt

http --auth-type=jwt --auth="eyJ0eXAi..." localhost:8000/api/users

CURL

curl -X GET localhost:8000/api/users -H "Authorization: BEARER eyJ0eXAi..."

Refresh JWT Token after expiration

Your JWT Token is set to expire at a certain time that is set in config/packages/lexik_jwt_authentication.yaml:

# Unit is in second. So 900 seconds.
token_ttl: 900

If your JWT Token expire, you will need to re-generate a new one with the second token provided when you login, called refresh_token, the refresh_token can only be used once, but everytime you request a new JWT Token you will get a new refresh_token as well:

{
    "refresh_token": "b1ca3f...",
    "token": "eyJ0eXAi..."
}

Retrieve a new valid JWT Token:

httpie

http POST localhost:8000/api/token/refresh refresh_token=b1ca3f...

CURL

curl -X POST -H "Content-Type: application/json" localhost:8000/api/token/refresh -d '{"refresh_token": "b1ca3f..."}'

With this new token, you will be able to fetch data from the API again.


Setup crontab

Run:

crontab -e

add the following line, change <PATH_TO_PROJECT> to your Project PATH:

0 0 * * * cd ~/<PATH_TO_PROJECT>/agora-api && ./bash_scripts/launch-schedule.sh >> /dev/null 2>&1

Mac OS Catalina cron Permission Troubleshooting

Open folder containing cron binary file:

open /usr/sbin
  • Go to your System Settings > Security & Privacy > Disk access

  • Click on the lock at the bottom left corner and enter your password

  • Drag and drop the cron binary file into your System Settings Window.

  • Cross the checkbox next to it.

Then it should fix the permission problem.


Commands

Makefile

Prefix the following names with make:

NAME DESCRIPTION
start Start the server
stop Stop the server
cc Clear the cache
router List all routes
log Display server logs
test Run all tests
test-file Run a specific test file that user enter. Example: UserTest
install Install dependencies
db-create Create the database
db-migration Launch migrations
db-fixture Load fixtures
db-update Run db-migration and db-fixture
swagger Update swagger documentation

SQL

MCD

alt text

MLD

alt text

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.