Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check user making request from API #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,44 @@ function atomarch_google_auth() {
return true;

} else {

if (!isset($_GET['code'])) {

// Generate a URL to request access from Google's OAuth 2.0 server
$auth_url = $client->createAuthUrl();
// Redirect the user to $auth_url so they can enter their Google credentials
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));

} else {
// Exchange an authorization code for an access token
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);

if (!array_key_exists('access_token', $token)) {
yourls_e("invalid token");
die();
}
//Store Access Token in a session variable
$_SESSION['access_token'] = $token;

if (atomarch_check_domain($client) === false) {
$client->revokeToken();
unset($_SESSION['access_token']);
yourls_e("User from Unauthorized Domain.");
die();

// If user sending request with API, check user credentials
if(yourls_is_API()){

yourls_check_username_password();

}else{

if (!isset($_GET['code'])) {

// Generate a URL to request access from Google's OAuth 2.0 server
$auth_url = $client->createAuthUrl();
// Redirect the user to $auth_url so they can enter their Google credentials
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));

} else {
// Exchange an authorization code for an access token
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);

if (!array_key_exists('access_token', $token)) {
yourls_e("invalid token");
die();
}

$redirect_uri = yourls_admin_url();
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
//Store Access Token in a session variable
$_SESSION['access_token'] = $token;

if (atomarch_check_domain($client) === false) {
$client->revokeToken();
unset($_SESSION['access_token']);
yourls_e("You can only access it with an ILA account.");
die();
}

$redirect_uri = yourls_admin_url();
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
}

}
}

Expand Down