查看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。通过强制用户转到他们的页面,它确保了一些事情:
- 用户知道他们正在使用外部服务,其服务条款可能与您的应用程序不同
- 让用户了解您的应用程序为该服务请求的功能。在 dwolla 的案例中,您的应用程序可以请求不同级别的功能,包括转账,因此让您的用户了解这一点很重要!
您可以在 http://oauth.net/ 阅读更多关于 OAuth 的信息
关于php - 使用 AJAX 生成 Dwolla 访问 token 而不是重定向到他们的网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14289268/