Sign In with Github Tutorial
Introduction
Sign In with Github enables users to sign in to Apps using their Github accounts.
Prerequisites
To begin with this tutorial, you will need:
- An app created at Back4App.
- See the Create New App tutorial to learn how to create an app at Back4App.
- Set up a Subdomain for your Back4app app
- See Activating your Web Hosting and Live Query to learn how to create an subdomain in Back4App.
- A Github account.
Step 1 - Create a New Back4App App
First of all, it’s necessary to make sure that you have an existing app created at Back4App. However, if you are a new user, you can check this tutorial to learn how to create one.
Step 2 - Create a new Github App
Create a new Github Application by going to Applications/New
Fill up the Application name
, your Homepage URL
, a quick Description
and your Authorization callback URL
`

Then click Register Application
. You should then see your App Secret
and Client Secret

Step 3 - Retrieve your Code
Visit the following URL, changing the values for CLIENT_ID
for the one you created.
1
https://github.com/login/oauth/authorize?scope=user:email&client_id=CLIENT_ID
Log in with your Github account:


and the redirected website will have your code in the URL:
Copy the Code part of the URL only and run the following CURL command replacing the values YOUR_CODE
, YOUR_CLIENT_ID
and YOUR_CLIENT_SECRET
for the values of your application
1
2
3
4
5
6
curl -X POST \
-F \'client_id=YOUR_CLIENT_ID'
-F 'client_secret=YOUR_CLIENT_SECRET'
-F 'code=YOUR_CODE'
-F 'accept=json'
https://github.com/login/oauth/access_token
Run it and you should retrieve your access token:
REMEMBER: the code can be used only once. If you get an error or don’t use your token, you must re-generate your Code to be able to run it again.
Step 4 - Start the development
Now that the Sign In with Github is configured, you can start the development process.
The format for AUTHDATA is:
1
2
3
4
5
6
{
"github": {
"id": "user's Github id (string)",
"access_token": "an authorized Github access token for the user"
}
}
Here is the method for the iOS SDK:
1
2
3
PFUser.logInWithAuthType(inBackground: "github", authData: ["access_token":tokenString, "id": user]).continueWith { task -> Any? in
}
And here for the Android SDK:
1
2
3
4
5
6
Map<string, string, bool> authData = new HashMap<string, string, bool>();
authData.put("access_token", tokenString);
authData.put("id", user);
ParseUser.logInWithInBackground("github", authData){
}