web.config文件行拒绝访问Google OAuth登录

时间:2014-03-04 09:37:27

标签: asp.net asp.net-mvc web-config

在web.config文件中的行:

<authorization>
  <deny users="?" />
</authorization> 

拒绝访问Google OAuth登录信息(使用OAuthWebSecurity)。 当我们对这些行进行评论时,它会起作用,但有人在此说这些行是出于安全原因而需要的。

有没有其他方法可以让Google OAuth登录无需注释这些行?

1 个答案:

答案 0 :(得分:0)

我没有任何代码就得到了OAuth:P(使用PHP)

以下代码使用OAuth2.0对连接进行身份验证,它会在您选择的可选谷歌日历上创建一个事件,并使用一个简单的表单来添加事件细节。

经过测试,我有这个工作&amp;也是一个不同的版本,通过外部表单将事件详细信息作为变量传递,并且连接使用服务帐户而不是OAuth2.0

祝你好运。

<?php
require_once '../google-api-php-client/src/Google_Client.php';
require_once '../google-api-php-client/src/contrib/Google_CalendarService.php';
session_start();

$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Event Creator");

$client->setClientId('YOUR CLI ID HERE.apps.googleusercontent.com');
$client->setClientSecret('YOUR CLI SECRET HERE');
$client->setRedirectUri('THIS FILE LOCATION HERE');
$client->setDeveloperKey('API key here');

$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])){
unset($_SESSION['token']);
}

if (isset($_GET['code'])){
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}

if (isset($_SESSION['token'])){
$client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()){
$calList = $cal->calendarList->listCalendarList();

if(isset($_POST['action'])){
$action = $_POST['action'];

if($action == "addCalEvent"){
$title = $_POST["title"];
$desc = $_POST["desc"];
$calID = $_POST["calID"];
$locat = $_POST["locat"];
$from = $_POST["from"];
$until = $_POST["until"];

//Set the Event data
$event = new Google_Event();
$event->setSummary($title);
$event->setDescription($desc);
$event->setLocation($locat);
$start = new Google_EventDateTime();
$start->setDateTime($from);
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($until);
$event->setEnd($end);

$createdEvent = $cal->events->insert('YOUR CALENDAR ID HERE@group.calendar.google.com', $event);

echo $createdEvent->getId();
}
}

print "<div style='width:100%;height:100%;'><div style='width:550px;height:320px;text-align:center;margin:200px auto;background-color:#f0ffff;border:1px solid black;'><div style='padding:50px;'><table>";
print "<form action='caladd.php' method='POST'>";
print "<tr><td>Title: </td><td><input type='text' name='title' id='title'></td></tr>";
print "<tr><td>Desc: </td><td><input type='text' name='desc' id='desc'></td></tr>";
print "<tr><td>Location: </td><td><input type='text' name='locat' id='locat'></td></tr>";
print "<tr><td colspan='2'>Date Format: YYYY-MM-DDTHH:MM:SS(.000)-00:00 (.000 = Optional)</td></tr>";
print "<tr><td>From: </td><td><input type='text' name='from' id='from'></td></tr>";
print "<tr><td>To: </td><td><input type='text' name='until' id='until'></td></tr>";
print "<tr><td>Select Calendar: </td><td><select name='calID' id='chooseCal'>";
for($i=0; $i < count($calList['items']); $i++)
{
print "<option value=".$calList['items'][$i]['id']."'>".$calList['items'][$i]['summary']."</option>";

}
print "</select></br></td></tr>";
print "<input type='hidden' name='action' value='addCalEvent'>";
print "<tr><td colspan='2'><div style='text-align:right;'><input type='submit' value='Submit'></div></td></tr>";
print "</form>";
print "</table></div></div></div>";

$_SESSION['token'] = $client->getAccessToken();
}
else
{
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Create a Google Calendar Event?</a>";
print "<a href='/'>Exit to Homepage</a>";
}
?>