Martin Muriuki
2 min readOct 22, 2018

Creating JWT Token Authentication

I would like to share my experience at Andela boot-camp. I would honestly say that I have learned a lot based on the challenges we have been given and it made me think in certain ways that I never imagined I would able to solve in shortest time possible, like in challenge 2 , We were supposed to create at least a minimum of six API endpoints, I managed to implement them without a sweat. Then an update of the mentioned challenge came to 2 days before submission, We were supposed to add 2 authorization endpoints in order for specific users to access certain endpoints (to be specific creating JWT token. I had no idea how to implement it so I had to ask my colleague in my group on how to do it. He gave tried to explain it but still didn’t understood the concept of it.
Luckily, another guy in our the boot-camp slacked an article in the group channel I had to check. The author explained in a simple and concise manner on how JWT work in a step by step format with an illustrated code. I tried it to implement on my end and It worked !!!. The only setback was that the code was one file and runs alone as flask application. I needed to figure out the way on how to integrate my application, and so I had to do more research.
After doing some research, I installed flask_jwt_extended in my project virtual environment then broken down the code in major parts, First part I put the JWT SECRET KEY and its code configuration in the __init__py that was in the app folder. the second part of the code I created was authorization model to structure my data and the last part was the main code that stored registration, the login and its authentication method. I ran the application it worked without a hitch!!
It was now time to check if it works on Postman to check my endpoints. I logged in successfully but didn’t get a token. I scratched my head thinking on what went wrong. It took me 2 hours to realize I did not import the authorization model correctly on my main code. It finally works. I logged and got the token

I was relieved that I managed to implement the endpoints on time and gave me a sense of confidence. I believed without that pressure I would never have learned about it. I would just keep that notion of not achieving the stated task.