For your enjoyment this project provides a basic Ionic app and Express server with functionality for user authentication using bearer tokens, as specified by RFC 6750.
- Download project.
- Run
npm install
in bothmobile
andserver
directories. - Modify
conf.js
inserver
directory to connect to your MongoDB. - Run
mongod
. - Run
gulp
inserver
directory to start server. - Run
ionic serve
orionic build ios; ionic emulate ios;
inmobile
directory. - Eat cookies
If using ionic serve
I used this solution to do HTTP requests right from the browser.
This project has not been tested in an production enviroment, so the API may not work without the Access-Control-Allow-Origin
being set properly.
The mobile app is very basic. It starts you off in a "Welcome" screen that has one button Create Profile
. This transitions you into a Create Profile
page. After creating a profile and storing the authToken
in the device's local storage, it transitions you to a sample page where you can get a user from the protected /api/user/get
route. You can also test the 401
server response on this page by clearing out the authToken
and requesting a user from /api/user/get
. This causes the mobile app to display a Login Modal
that requires to first authenticate, and then proceeds to get the user.
Thanks to KD Moore Consulting which provides a more detailed look at this process.
I finally figured out how to link up my Ionic App with a backend using bearer tokens for authentication, so I wanted to provide a solution that will hopefully help you on your journey to creating mobile apps.