php - 使用 AJAX 生成 Dwolla 访问 token 而不是重定向到他们的网页?

标签 php redirect oauth paypal dwolla

查看Dwolla's API documentation并尝试 oauth.php example code (code shown below)在我的网站上,我不清楚是否可以在不重定向到 Dwolla 页面的情况下生成访问 token 。

从 UI/UX 的角度来看,从我的网站重定向到他们的网站再回到我的网站真的很糟糕,并不比 Paypal 提供的糟糕界面好多少。

有谁知道如何使用 AJAX 生成 Dwolla 访问 token ?



<?php
// Include the Dwolla REST Client
require '../lib/dwolla.php';

// Include any required keys
require '_keys.php';

// OAuth parameters
$redirectUri = 'http://localhost:8888/oauth.php'; // Point back to this file/URL
$permissions = array("Send", "Transactions", "Balance", "Request", "Contacts",   "AccountInfoFull", "Funding");

// Instantiate a new Dwolla REST Client
$Dwolla = new DwollaRestClient($apiKey, $apiSecret, $redirectUri, $permissions);

/**
 * STEP 1: 
 *   Create an authentication URL
 *   that the user will be redirected to
 **/

if(!isset($_GET['code']) && !isset($_GET['error'])) {
$authUrl = $Dwolla->getAuthUrl();
header("Location: {$authUrl}");
}

/**
 * STEP 2:
 *   Exchange the temporary code given
 *   to us in the querystring, for
 *   a never-expiring OAuth access token
 **/
 if(isset($_GET['error'])) {
echo "There was an error. Dwolla said: {$_GET['error_description']}";
}

else if(isset($_GET['code'])) {
$code = $_GET['code'];

$token = $Dwolla->requestToken($code);
if(!$token) { $Dwolla->getError(); } // Check for errors
else {
    session_start();
    $_SESSION['token'] = $token;
    echo "Your access token is: {$token}";
} // Print the access token
}

最佳答案

TL;DR - 不,那不是 OAuth 的工作方式


OAuth 方案的重点是在您要使用的服务网站上进行身份验证,在本例中为 Dwolla。通过强制用户转到他们的页面,它确保了一些事情:

  1. 用户知道他们正在使用外部服务,其服务条款可能与您的应用程序不同
  2. 让用户了解您的应用程序为该服务请求的功能。在 dwolla 的案例中,您的应用程序可以请求不同级别的功能,包括转账,因此让您的用户了解这一点很重要!

您可以在 http://oauth.net/ 阅读更多关于 OAuth 的信息

关于php - 使用 AJAX 生成 Dwolla 访问 token 而不是重定向到他们的网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14289268/

相关文章:

php - 从 PHP 中的动态表单向数据库添加行

actionscript-3 - "SecurityError: Error #2122"从重定向图像加载内容

redirect - 使用 ColdFusion Model-Glue,如何在登录后将用户重定向回他们请求的页面?

ruby-on-rails - 未定义的方法 'add_acts_as_authentic_module'

php - 如何连接两个截然不同的mysql表,并同时按两列排序?

php - 获取两个日期之间一定时间内的记录

php - 十月 CMS - 如何正确路由

bash - AWK:将脚本输出从脚本重定向到另一个具有动态名称的文件

authentication - 如何实现Office 365 OAuth2登录认证的跨域请求?

php - Laravel REST API - 无限循环