Ionic 2+ Github

Setup your application's code

npm install angular2-jwt@0.1.27 --save

Add the following lines to your base code

// src/services/auth/auth.service.ts

import { Storage } from '@ionic/storage';
import { AuthHttp, JwtHelper, tokenNotExpired } from 'angular2-jwt';
import { Injectable, NgZone } from '@angular/core';
import { Observable } from 'rxjs/Rx';

// Avoid name not found warnings
declare var Auth0: any;
declare var Auth0Lock: any;

export class AuthService {

  jwtHelper: JwtHelper = new JwtHelper();
  auth0 = new Auth0({clientID: Auth0Vars.AUTH0_CLIENT_ID, domain: Auth0Vars.AUTH0_DOMAIN });
  lock = new Auth0Lock(Auth0Vars.AUTH0_CLIENT_ID, Auth0Vars.AUTH0_DOMAIN, {
    auth: {
      redirect: false,
      params: {
        scope: 'openid profile offline_access',
        device: 'my-device'
      sso: false
  storage: Storage = new Storage();
  refreshSubscription: any;
  user: Object;
  zoneImpl: NgZone;
  accessToken: string;
  idToken: string;
  constructor(private authHttp: AuthHttp, zone: NgZone) {
    this.zoneImpl = zone;
    // Check if there is a profile saved in local storage'profile').then(profile => {
      this.user = JSON.parse(profile);
    }).catch(error => {
    });'id_token').then(token => {
      this.idToken = token;

    this.lock.on('authenticated', authResult => {
      if (authResult && authResult.accessToken && authResult.idToken) {'access_token', authResult.accessToken);'id_token', authResult.idToken);'refresh_token', authResult.refreshToken);
        this.accessToken = authResult.accessToken;
        this.idToken = authResult.idToken;

        // Fetch profile information
        this.lock.getUserInfo(this.accessToken, (error, profile) => {
          if (error) {
            // Handle error

          profile.user_metadata = profile.user_metadata || {};
'profile', JSON.stringify(profile));
          this.user = profile;

        this.lock.hide(); => this.user = authResult.profile);
        // // Schedule a token refresh


  public authenticated() { 
    return tokenNotExpired('id_token', this.idToken);
  public login() {
    // Show the Auth0 Lock widget;
  public logout() {'profile');'access_token');'id_token');
    this.idToken = null;'refresh_token'); => this.user = null);
    // Unschedule the token refresh

Create an Application in Auth0 dashboard 

Create an Application in Auth0 dashboard

Create a Social Github Connection under Connections / Social section

Create a Social Connection for authentication
Authentication Security and Availability

Authentication Built for Security & High Availability

Auth0 is the easiest way for developers to integrate enterprise-grade authentication and identity management to any app.

Industry Standard Compliance
Authentication Certifications and Compliance

SOC 2, HIPAA/BAA, EU/US Privacy Shield Framework, Open ID Certified.

Learn More
Built by Security Experts
uthentication Experts

Continuously reviewed and tested by external security experts. Strong password encryption and hashing algorithms, at rest and in transit.

Learn More
What Our Customers Say
Authentication Case Studies

Continuously reviewed and tested by external security experts. Strong password encryption and hashing algorithms, at rest and in transit.

Learn More
Availability & trust
Authentication Availability

Uptime time in 3 different regions.

Learn More
Host Anywhere
Auth0 Appliance

Deploy On-Premises or on Cloud on your data center or Auth0’s one.

Learn More
Auth0 Active Users

Get Auth0 free for 7,000 active users per month with unlimited logins

  • Single Sign On
  • Passwordless Login
  • Up to 2 Social Identity Providers
  • Multifactor Authentication
  • User Management
  • Extensibility (Run custom code on Auth)

Some of the companies that trust us every day

Atlassian - Authentication CustomerPBS - Authentication CustomerNVIDIA - Authentication CustomerMozilla - Authentication CustomerBluetooth - Authentication CustomerFinancial Times - Authentication CustomerJet - Authentication CustomerHMH - Authentication CustomerOptimizely - Authentication CustomerPolaris - Authentication CustomerHarper - Authentication CustomerNews Corp - Authentication Customer