You're viewing the legacy docs. They are deprecated as of May 18, 2016.
These docs are for version 2.5.1 and below of the Objective-C SDK. Go to our current docs, or see our iOS migration guide.

Objective-C and Swift iOS Guide

Github Authentication

Configuring Your Application

To get started with GitHub authentication, you need to first create a new GitHub application. Click the Register new application button at the top right of that page and fill in a name, description, and website for your application.

After configuring your GitHub application, head on over to the Login & Auth section in your App Dashboard. Enable GitHub authentication and then copy your GitHub application credentials (Client ID and Client Secret) into the appropriate inputs. You can find your GitHub application's client ID and secret at the top of the application's GitHub dashboard.

Authenticating Github users to your Firebase App

Once you have enabled Github authentication in Firebase, you can take advantage of the Security and Firebase Rules to protect your data.

To log a user into your Firebase, you will need a Github OAuth access token. Once you have the token, you can pass it to authWithOAuthProvider:token:withCompletionBlock:

Firebase *ref = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com"];
[ref authWithOAuthProvider:@"github" token:ACCESS_TOKEN
    withCompletionBlock:^(NSError *error, FAuthData *authData) {

    if (error) {
        // There was an error logging in
    } else {
        // We have a logged in Github user
    }
}];
let ref = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com")
ref.authWithOAuthProvider("github", token:ACCESS_TOKEN,
    withCompletionBlock: { error, authData in

    if error != nil {
        // There was an error during log in
    } else {
        // We have a logged in Github user
    }
})

The FAuthData object returned to your block contains the following fields:

FAuthData
Field Description Type
uid A unique user ID, intended as the user's unique key across all providers. NSString
provider The authentication method used, in this case: github. NSString
token The Firebase authentication token for this session. NSString
auth The contents of the authentication token, which will be available as the auth variable within your Security and Firebase Rules. NSDictionary
expires A timestamp, in seconds since the UNIX epoch, indicating when the authentication token expires. NSNumber
providerData A dictionary containing provider-specific data. NSDictionary
providerData[@"id"] The Github user's ID. NSString
providerData[@"accessToken"] The Github OAuth 2.0 access token granted by Github during user authentication. NSString
providerData[@"displayName"] The Github user's full name. NSString
providerData[@"email"] The GitHub user's primary, verified email address as listed on their profile. Returned only if a primary, verified email address is available, and the GitHub user:email scope was granted by the user. NSString
providerData[@"username"] The Github user's username. NSString
providerData[@"profileImageURL"] The URL of the Github user's profile picture. NSString
providerData[@"cachedUserProfile"] The GitHub user's raw profile, as specified by GitHub's user documentation. Note that the data included in this payload is generated by GitHub and may be changed by them at any time. NSDictionary

Security & Rules

Now that the client is logged in, your Security and Firebase Rules have access to their verified unique user ID. The auth variable contains the following values:

auth Variable
Field Description Type
uid A unique user ID, intended as the user's unique key across all providers. String
provider The authentication method used, in this case: github. String

Here is an example of how to use the auth variable in your Security and Firebase Rules:

{
  "rules": {
    "users": {
      "$uid": {
        // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
        ".write": "auth !== null && auth.uid === $uid",

        // grants read access to any user who is logged in with Github
        ".read": "auth !== null && auth.provider === 'github'"
      }
    }
  }
}
See the User Authentication and User Based Security articles for more details.
  1. 1

    Next

    Installation & Setup

  2. 2

    Next

    Understanding Data

  3. 3

    Next

    Saving Data

  4. 4

    Next

    Retrieving Data

  5. 5

    Next

    Structuring Data

  6. 6

    Next

    Understanding Security

  7. 7

    Next

    User Authentication

  8. 8

    Next

    Offline Capabilities