English 中文(简体)
采用冷聚法进行表面核查
原标题:Error with facebook verification code using coldfusion

我有一份正使用氟氯化碳I的书本申请,该书在RIAForge上发现,用于认证用户/申请,并允许许可(,但不再有效。 因此,我准备撰写一个版本的。 Fox s PHP example as CFML. 但是,当我回过来回去找回被证明的人时,我从脸书上发现了以下错误:

OAuth “Facebook Platform”“invalid_code” “Error validating ratification Code”

由于我测试了由他们提供的带我详细内容的购买力平价代码,并做了一些细微的工作,所以在打上手提书时没有问题。 请参看PHP的例子,以及我不得不使用CF的情况。

PHP:

$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$my_url = "YOUR_URL";

session_start();
$code = $_REQUEST["code"];

if(empty($code)) {
 $_SESSION[ state ] = md5(uniqid(rand(), TRUE)); //CSRF protection
 $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
   . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
   . $_SESSION[ state ];

 echo("<script> top.location.href= " . $dialog_url . " </script>");
 }

 if($_REQUEST[ state ] == $_SESSION[ state ]) {
 $token_url = "https://graph.facebook.com/oauth/access_token?"
   . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
   . "&client_secret=" . $app_secret . "&code=" . $code;

 $response = @file_get_contents($token_url);
 $params = null;
 parse_str($response, $params);

 $graph_url = "https://graph.facebook.com/me?access_token=" 
   . $params[ access_token ];

 $user = json_decode(file_get_contents($graph_url));
 echo("Hello " . $user->name);
 }
 else {
 echo("The state does not match. You may be a victim of CSRF.");
 }

 ?> 

CFML:

<cfset appID = "app_id"/>
<cfset secret_key = "secret_key"/>
<cfset app_url = "app_url"/>

<cfparam name="URL.Code" default="0">
<cfparam name="URL.State" default="0">
<cfset code_ = URL.Code>

<cfif code_ EQ "" OR code_ EQ 0>
  <cfset SESSION.State = Hash(CreateUUID(),"MD5")>
  <cfset dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" & appID &    "&redirect_uri=" & app_url & "?State=" & SESSION.State>
  <cf_Javascript type="script" script="top.location.href= #dialog_url# ">
</cfif>

<cfif SESSION.State EQ URL.State>
  <cfset token_url = "https://graph.facebook.com/oauth/access_token?client_id=" & appID & "&redirect_uri=" & app_url & "&client_secret=" & secret_key & "&code=" & code_>
  <cfhttp url="#token_url#" result="AccessToken" method="GET">
  <cfdump var="#AccessToken#">
</cfif>
最佳回答

我感到非常困惑,在确定URL参数时,我使用了问题标记,而不是安放器。

问题回答

您没有显示这一变量的数值,因此我们不知道你是否重新加入该变量。

<cfset app_url = "app_url"/>

我大概不谈。 因此,对于开户人来说,你要么想做:

<cfset app_url = urlEncodedFormat("app_url") />

<cfset dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
  & appID 
  & "&redirect_uri=" 
  & urlEncodedFormat(app_url)
  & "?State=" 
  & SESSION.State
/>

否则,你会回到正确的轨道上来。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签