Problem Statement: Ionic 2 App authenticates using Auth0 and then using Auth0 token to firebase API as backend without using firebase authentication.
Solution: I have created base version of this project in GitHub. You can clone it from here.
1. Clone the project
2. npm install ionic cordova typescript -g
3. After cloning project, run npm install for all local packages to install.
I am using facebook authentication with Auth0, so first we need to create facebook app in developer console.
Once you got application Id and App Secret then add the following Auth0 callback url on successful authentication. Fore new Apps, you need to add facebook login by clicking on “Add product” and then go to “Settings” to add callback Url.
Create Firebase app in console.
Now we need to get Api key to integrate to Auth0. Click on seetings icon.
Now go to Service Accounts and then click “Generate Private Key” downloads JSON. we will use this information in Auth0 Configuration.
Next need to get firebase config, for this go to Overview-> Add to web. this configuration is used in appmodule.ts
Create Auth0 Account
Now go to social connection and select facebook. Enter application id,app secret, scope you need for your application.
Create new application with type “Native”. Change callback url if needed.
Now go to Addons tab and enable firebase. Fill information in settings from the json file got from firebase.
Now go to connections tab in your app, go and enable facebook. if you remember we enabled facebook in social connection and then we add facebook for each and every app we work.
Now we will go through some of the code.
src/auth0-variables.ts: You will set Auth0 App details in this file before you run the application.
src/app/app.module.ts: We will configure angular fire module with firebase configuration info as shown above.
login() method shows Auth0 screen.
constructor() This has authentication callback where we get Auth0 token and then we can get firebase access token.