{"id":20159623,"url":"https://github.com/mosesesan/mesan-laravel-jwt-authentication-api","last_synced_at":"2025-10-11T07:42:42.476Z","repository":{"id":91998569,"uuid":"65034583","full_name":"MosesEsan/mesan-laravel-jwt-authentication-api","owner":"MosesEsan","description":"A PHP Mobile Authentication API with E-mail verification and Phone Verification using Twilio Authy, developed with Laravel 5.4 framework and JWT (JSON Web Tokens) Package. ","archived":false,"fork":false,"pushed_at":"2018-02-17T10:56:35.000Z","size":289,"stargazers_count":21,"open_issues_count":3,"forks_count":13,"subscribers_count":2,"default_branch":"email-verification","last_synced_at":"2025-04-09T23:39:03.260Z","etag":null,"topics":["email-verification","jwt","laravel","phone-verification","php","register","tutorial","twilio-authy"],"latest_commit_sha":null,"homepage":"https://medium.com/@mosesesan/tutorial-5-how-to-build-a-laravel-5-4-jwt-authentication-api-with-e-mail-verification-61d3f356f823","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MosesEsan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-05T16:49:20.000Z","updated_at":"2023-10-04T18:01:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"f9cc8284-3f04-4036-8557-168ce29dc5d0","html_url":"https://github.com/MosesEsan/mesan-laravel-jwt-authentication-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MosesEsan/mesan-laravel-jwt-authentication-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MosesEsan%2Fmesan-laravel-jwt-authentication-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MosesEsan%2Fmesan-laravel-jwt-authentication-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MosesEsan%2Fmesan-laravel-jwt-authentication-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MosesEsan%2Fmesan-laravel-jwt-authentication-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MosesEsan","download_url":"https://codeload.github.com/MosesEsan/mesan-laravel-jwt-authentication-api/tar.gz/refs/heads/email-verification","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MosesEsan%2Fmesan-laravel-jwt-authentication-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006624,"owners_count":26084131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["email-verification","jwt","laravel","phone-verification","php","register","tutorial","twilio-authy"],"created_at":"2024-11-14T00:09:20.748Z","updated_at":"2025-10-11T07:42:42.470Z","avatar_url":"https://github.com/MosesEsan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel 5.4 JWT Authentication API with E-Mail Verification\nA PHP Mobile Authentication API with E-mail verification, developed with Laravel 5.4 framework and JWT (JSON Web Tokens) Package.\n\n**This Branch** \u003cbr/\u003e\nEmail Verification\n\n**Other Branch** \u003cbr/\u003e\n\u003ca href=\"https://github.com/MosesEsan/mesan-laravel-jwt-authentication-api/tree/phone-verification\" target=\"_blank\"\u003ePhone Verification using Twilio Authy\u003c/a\u003e\n\n## Testing\nUse Chrome plugin \u003ca href=\"https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en\" target=\"_blank\"\u003ePostman\u003c/a\u003e to test.\u003cbr/\u003e\n\n**Try accessing test route without token [GET]**\u003cbr/\u003e\n\nhttp://mosesesan.com/demos/jwt-email-auth/api/test\u003cbr/\u003e\n\nYou should receive the following error message.\n\n```json\n {\n     \"error\": \"token_not_provided\"\n }\n```\n\n**Register and Verify** \u003cbr/\u003e\nCreate a POST request to api/register with form-data under Body tab. **Make sure to enter a valid email address so you can receive the verification email.**\u003cbr/\u003e\n\nhttp://mosesesan.com/demos/jwt-email-auth/api/register\n\n```json\n{\n  \"success\":true,\n  \"message\":\"Thanks for signing up! Please check your email to complete your registration.\"\n}\n```\n\nVerify the email address by clicking the link in the verification email.\n\n**Login** \u003cbr/\u003e\nCreate a POST request to api/login with form-data under Body tab.\n\nhttp://mosesesan.com/demos/jwt-email-auth/api/login\n\nIf you attempt to login without verifying your email address, you will receive the error below:\n\n```json\n{\n    \"success\": false,\n    \"error\": \"Invalid Credentials. Please make sure you entered the right information and you have verified your email address.\"\n}\n```\n\nIf you have verified your email address, you should receive a token back\n\n```json\n{\n    \"success\": true,\n    \"data\": {\n        \"token\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjQsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODg4OC9tZXNhbi1sYXJhdmVsLWp3dC1hdXRoZW50aWNhdGlvbjIvcHVibGljL2FwaS9sb2dpbiIsImlhdCI6MTUwMjU2NzE5MSwiZXhwIjoxNTAyNTcwNzkxLCJuYmYiOjE1MDI1NjcxOTEsImp0aSI6IkVIVWV6dVp0UDhhSmQ2QUUifQ.OjlzNKmTItphLs29B7WsFstmrtgDW2qE7gv26LcR3Og\"\n    }\n}\n```\n\n**Try accessing test route with the token [GET]**\n\nhttp://mosesesan.com/demos/jwt-email-auth/api/test?token=[token_goes_here]\n\nYou should receive\n\n```json\n{\n    \"foo\": \"bar\"\n}\n```\n\n**Logout** \u003cbr/\u003e\nCreate a GET request to api/logout.\n\nhttp://mosesesan.com/demos/jwt-email-auth/api/logout?token=[token_goes_here]\n\n**Recover Password** \u003cbr/\u003e\nCreate a POST request to api/recover with form-data under Body tab.\n\nhttp://mosesesan.com/demos/jwt-email-auth/api/recover\n\n```json\n{\n    \"success\": true,\n    \"data\": {\n        \"msg\": \"A reset email has been sent! Please check your email.\"\n    }\n}\n```\n\n**Unique Email** \u003cbr/\u003e\n\nAttempt to register with the email address you used in the previous test.\n\n## Tutorial\n\nThe steps below are a compilation of a series of tutorials.\n\n\u003ca name=\"step1\"\u003e\u003c/a\u003e\n**Step 1: Create new project and install jwt-auth**\n\nCreate Laravel project\n```bash\nlaravel new JWTAuthentication\n```\nOpen composer.json and update the require object to include jwt-auth \n\n```php\n\"require\": {\n    \"php\": \"\u003e=5.6.4\",\n    \"laravel/framework\": \"5.4.*\",\n    \"laravel/tinker\": \"~1.0\",\n    \"tymon/jwt-auth\": \"0.5.*\"\n}\n```\n Then, run \n```bash\ncomposer update \n```\n\n\u003ca name=\"step2\"\u003e\u003c/a\u003e\n**Step 2: Add JWT Provider and Facades**\n \nWe’ll now need to update the providers array in config/app.php with the jwt-auth provider. Open up config/app.php, find the providers array located on line 138 and add this to it:\n\n```php\nTymon\\JWTAuth\\Providers\\JWTAuthServiceProvider::class, \n\n```\nAdd in the jwt-auth facades which we can do in config/app.php. Find the aliases array and add these facades to it:\n\n```php\n'JWTAuth'   =\u003e Tymon\\JWTAuth\\Facades\\JWTAuth::class, \n'JWTFactory' =\u003e Tymon\\JWTAuth\\Facades\\JWTFactory::class \n \n```\nWe also need to publish the assets for this package. From the command line: \n \n```bash\nphp artisan vendor:publish --provider=\"Tymon\\JWTAuth\\Providers\\JWTAuthServiceProvider\" \n \n```\n \nAfter you run this command you will see a new file in the config folder called jwt.php. This file contains settings for jwt-auth, one of which we need to change right away. We need to generate a secret key which we can do from the command line: \n```bash\nphp artisan jwt:generate \n \n```\n\nYou’ll see that after running this command we get a new value next to’secret’ where “changeme” was before.\n\nRegister the jwt.auth and jwt.refresh middleware in app/http/Kernel.php\n \n ```php\n protected $routeMiddleware = [\n ...\n     'jwt.auth' =\u003e 'Tymon\\JWTAuth\\Middleware\\GetUserFromToken',\n     'jwt.refresh' =\u003e 'Tymon\\JWTAuth\\Middleware\\RefreshToken',\n ];\n ```\n\n\u003ca name=\"step3\"\u003e\u003c/a\u003e\n**Step 3: Set Up Routes**\n\nOpen up routes/api.php.\n\n```php\nRoute::post('login', 'AuthController@login'); \nRoute::post('register', 'AuthController@register'); \nRoute::post('recover', 'AuthController@recover');\n \nRoute::group(['middleware' =\u003e ['jwt.auth']], function() { \n    Route::post('logout', 'AuthController@logout'); \n  \n    Route::get('test', function(){ \n        return response()-\u003ejson(['foo'=\u003e'bar']); \n    }); \n});\n```\nOpen up routes/web.php and add the route for verifying.\n\n```php\n....\nRoute::get('user/verify/{verification_code}', 'AuthController@verifyUser');\n```\n\n\u003ca name=\"step4\"\u003e\u003c/a\u003e\n**Step 4: Set Up Database**\n\nSince we are going to allow users to create their accounts within the application, we will need a table to store all of our users. Thankfully, Laravel already ships with a migration to create a basic users table, so we do not need to manually generate one. The default migration for the users table is located in the database/migrations directory.\n\nWe need to create a new table and add an extra column to the users table. Firstly, we need a boolean field ‘is_verified’to keep track of whether a user has verified their email address, this will be set to false by default.\n\nCreate new table “user_verifications” that will store token of user verification code. When a user is signed up, a verification code is generated and stored in the table, an email is then sent to the user asking them to verify their account by following a link to /user/verify/{verification_code}.\n\nWhen a user follows this link, we take the passed in verification code and search for it within the user_verifications table. If a matching verified code is found we set the is_verified field for this user to true.\n\nThe full tutorial is available on my  \u003ca href=\"https://medium.com/@mosesesan/tutorial-5-how-to-build-a-laravel-5-4-jwt-authentication-api-with-e-mail-verification-61d3f356f823\" target=\"_blank\"\u003eblog\u003c/a\u003e.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmosesesan%2Fmesan-laravel-jwt-authentication-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmosesesan%2Fmesan-laravel-jwt-authentication-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmosesesan%2Fmesan-laravel-jwt-authentication-api/lists"}