talha/lumen-jwt-hashing

There is no license information available for the latest version (0.0.1) of this package.

Random hash generator api.

0.0.1 2019-06-28 12:27 UTC

This package is auto-updated.

Last update: 2024-04-28 23:48:33 UTC


README

Installation

Please check the official Lumen installation guide for server requirements before you start. Official Documentation

Download via composer

Run the following command in your CMD :

	composer create-project talha/lumen-jwt-hashing

Donwload Via Github

Clone the repository form Github

git clone git@github.com:MKhan777/hashing.git

Switch to the repo folder

cd hashing

Install all the dependencies using composer

composer install

Copy the example env file (from lumen sample project.The env file is not pre included in the project)and make the required configuration changes in the .env file

cp .env.example .env

Generate a new application key

Since Lumen doesn't have the php artisan key:generate command. You can create it online through any website or create it yourself.

Generate a random App key. Generate a random JWT authentication secret key

Run the database migrations (Set the database connection in .env before migrating)

php artisan migrate

Start the local development server

php -S localhost:8000 -t public

You can now access the server at http://localhost:8000

TL;DR command list

git clone git@github.com:MKhan777/hashing.git
cd lumen-jwt
composer install
cp .env.example .env

Make sure you set the correct database connection information before running the migrations Environment variables

php artisan migrate
php -S localhost:8000 -t public

Database seeding

Populate the database with seed data with relationships which includes users, articles, comments, tags, favorites and follows. This can help you to quickly start testing the api or couple a frontend and start using it with ready content.

Run the database seeder and you're done

php artisan db:seed

Note : It's recommended to have a clean database before seeding. You can refresh your migrations at any point to clean the database by running the following command

php artisan migrate:refresh

** Run composer dump autoload for files autoloading

composer dump-autoload

API Specification

Code overview

The code has three basic endpoints get(hash),post(login),post(\register). Use the Postman API builder interface to hit on these urls

	/register
	provide parameters  
		{
		"name"  : "sample",
		"email" : "sample@sample.com",
		"password" : "sample123"
		}

You will get a token in response.

		/login
		provide parameters
		{
		
		"email" : "sample@sample.com",
		"password" : "sample123"
		}

You will get a token in response.

	/hash
	provide parameters
	{
		token : "xyzxvyzsvyz"
	}

The same token that has been generated by login or register can be used here for hitting the output will be a hash that,ll be stored in log file

Dependencies

  • [firebase/php-jwt] - For authentication using JSON Web Tokens
  • [fzaninotto/faker] - For fake model generating 10 users (testing)
  • [phpunit/phpunit] - For unit tests

Environment variables

  • .env - Environment variables can be set in this file

Note : You can quickly set the database information and other variables in this file and have the application fully working.

Testing API

Run the Lumen development server

php -S localhost:8000 -t public

The api can now be accessed at

http://localhost:8000/api

Request headers

Required Key Value
Yes Content-Type application/json
Yes X-Requested-With XMLHttpRequest
Optional Authorization Token {JWT}

Refer the api specification for more info.

Authentication

This applications uses JSON Web Token (JWT) to handle authentication. The token is passed with each request using the Authorization header with Token scheme. The JWT authentication middleware handles the validation and authentication of the token. Please check the following sources to learn more about JWT.