Github Authentication

Setup

Create a Github App

The first step in setting up a Github authentication integration is to create an app on Github.

Client ID & Secret

Now that you’ve got an app setup, you need to let us know about the Client ID and Client Secret. Click your newly created app to reveal them.

App Implementation

Setup

Plugin Installation

The InAppBrowser plugin is used to login your users with Github authentication.

$ cordova plugin add cordova-plugin-inappbrowser --save

Injecting Auth and User

Import Auth and User from the Cloud Client and specify them as dependencies in your component constructor.

  • auth is a service that deals with user authentication.
  • user is a reference to the current user, whether that user is anonymous or authenticated.
import { Component } from [email protected]/core';
import { Auth, User } from [email protected]/cloud-angular';

@Component( ... )
export class LoginPage {
  constructor(public auth: Auth, public user: User) {
    ...
  }
}

Specify ionic.cloud as a dependency for your module. This gives you access to $ionicAuth and $ionicUser.

  • $ionicAuth is a service that deals with user authentication.
  • $ionicUser is a reference to the current user, whether that user is anonymous or authenticated.
angular.module('myapp.controllers', ['ionic.cloud'])

.controller('MyCtrl', function($scope, $ionicAuth, $ionicUser) {
  ...
})

Login

this.auth.login('github').then( ... );
$ionicAuth.login('github').then( ... );

Logout

Logging out clears the current user context.

this.auth.logout();
$ionicAuth.logout();

Social Data

We store social data in user.social.github. Unlike your custom data which uses user.get() and user.set(), user.social.github is just an object with the following properties.

uid Github user ID
data Github data object
data.profile_picture Github profile picture
data.email Github email
data.full_name The user’s full name
data.raw_data The data object straight from Github (see these docs)

Examples:

const full_name = this.user.social.github.data.full_name;
const profile_picture = this.user.social.github.data.profile_picture;
const github_raw_data = this.user.social.github.data.raw_data;
var full_name = $ionicUser.social.github.data.full_name
var profile_picture = $ionicUser.social.github.data.profile_picture
var github_raw_data = $ionicUser.social.github.data.raw_data;

Services

    API

      General