Hello,
i have issues with redirect URI, when i want to log in google oauth2, it doesnt redirect me and gimme Error 400: redirect_uri_mismatch
access_type=online
approval_prompt=auto
scope=https://www.googleapis.com/auth/calendar
response_type=code
redirect_uri=http://www.meetingroomapp.com/dashboard/oauth2callback.php
state=
client_id=825645938882-ftcv0fuojum9078uht1n8hpgbvp9ej3f.apps.googleusercont
There is code in index.php
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
SOME CODE HERE
} else {
$redirect_uri = 'http://www.meetingroomapp.com/dashboard/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
There is code in oauth2callback.php
session_start();
$client = new Google_Client();
$client->setAuthConfigFile('client_secret.json');
$client->setRedirectUri('http://www.meetingroomapp.com/dashboard/');
$client->addScope("https://www.googleapis.com/auth/calendar");
if (! isset($_GET['code'])) { //přesměrování na google server
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect_uri = 'http://www.meetingroomapp.com/dashboard/';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
There is secret JSON
{"installed":{"client_id":"**ID**","project_id":"meetinroomapp","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"**SECRET**","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://www.meetingroomapp.com/dashboard/"]}}
In Google developer console i have set http://www.meetingroomapp.com/dashboard/ as homepage
redirect mismatch happens when the redirect uri you specified in you request doesnt match the one you specified in google developer console.so check if the the redirect uri you specfied in google developer console is http://www.meetingroomapp.com/dashboard/oauth2callback.php