Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // get current url
- $current_url = $_SERVER['REQUEST_URI'];
- // if user is currently on registration page
- if (strpos($current_url, 'registration') !== false) {
- // require proper directory for config.php
- require_once 'models/config.php';
- // if user is not on registration page...
- } else {
- // require proper directory for config.php
- require_once '../models/config.php';
- }
- // require other necessary files;
- require $DBphp_location;
- require 'discord_oauth.php';
- $redirectURL = $discord_redirect_url; //The URL that the user will be redirect back too
- $clientID = 'xxx'; //The ID of the client
- $clientSecret = 'xxx'; //The sensitive and secret key of the client
- $scope = 'identify email';
- function getUserId($code) {
- require '../models/config.php';
- $redirectURL = $discord_redirect_url; //The URL that the user will be redirect back too
- $clientID = 'xxx'; //The ID of the client
- $clientSecret = 'xxx'; //The sensitive and secret key of the client
- $scope = 'identify email';
- //Exchange the token
- $auth = discord_oauth_exchange($clientID, $clientSecret, $scope, $redirectURL, $code);
- echo '<strong>'.$redirectURL.'</strong><br />';
- if ($auth == null || !empty($auth['error'])) {
- printf('Failed: Authorization was bad: %s', $auth['error']);
- return -1;
- }
- $user = discord_oauth_get('/users/@me', $auth['access_token']);
- if ($user == null || !empty($user['message'])) {
- printf('Failed: /users/@me threw a error: %s', $user['message']);
- return -1;
- }
- return intval($user['id']);
- }
- // get current URL
- $currentURL = $_SERVER['REQUEST_URI'];
- // if currentURL contains 'discord'
- if (strpos($currentURL, 'discord') !== false) {
- // If we don't have a code, redirect user
- if (!isset($_GET['code'])) {
- discord_oauth_redirect($clientID, $scope, $redirectURL);
- exit;
- }
- }
- //printf("<pre>\nCode: %s\nUser ID: %d", $_GET['code'], getUserId($_GET['code']));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment