Skip to content

Instantly share code, notes, and snippets.

View Pepijn1908's full-sized avatar

Pepijn van den Berkhof Pepijn1908

View GitHub Profile
@Pepijn1908
Pepijn1908 / github-oauth2-client.php
Last active July 4, 2017 08:47
Simple PHP example of using Github's OAuth 2 API
<?php
define('OAUTH2_CLIENT_ID', 'YOUR APP CLIENT ID HERE');
define('OAUTH2_CLIENT_SECRET', 'YOUR APP CLIENT SECRET HERE');
$authorizeURL = 'https://github.com/login/oauth/authorize';
$tokenURL = 'https://github.com/login/oauth/access_token';
$apiURLBase = 'https://api.github.com/';
session_start();
// Start the login process by sending the user to Github's authorization page
if(isset($_GET['action']) && $_GET['action'] == 'login'){
// Generate a random hash and store in the session for security