- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我决定将 bshaffer 的库用于 OAuth2.0 ( https://bshaffer.github.io/oauth2-server-php-docs/ )。我正在使用它为我的 API 实现客户端凭证授权类型。请求访问 token 时(使用硬编码的 client_id 和 client_secret),一切正常。我通过以下内容
grant_type => client_credentials
client_id => oauthuser
client_secret => xkJ7ua2p9zaRQ78YxYAfTCKGUaGEfMS6
结果如下:
{
"access_token": "855b36508abfdfcd25281e36020ab48917d4a637",
"expires_in": 3600,
"token_type": "Bearer",
"scope": null
}
但是每当我使用这个作为标题请求我的数据时:
authorization => Bearer 855b36508abfdfcd25281e36020ab48917d4a637
我收到一条错误消息,指出我的 token 无效:
{
"error": "invalid_token",
"error_description": "The access token provided is invalid"
}
我做错了什么?如演示应用程序所示,client_credentials 授权类型是否可以在没有授权授权类型的情况下使用?
这是我的一些代码:
对于初始化 OAuth 2.0 服务器的文件:
namespace App\Libraries;
use Silex\Application;
use Silex\ControllerProviderInterface;
use OAuth2\Storage\Memory as OAuth2MemoryStoraage;
use OAuth2\Server as OAuth2Server;
use OAuth2\GrantType\ClientCredentials;
use OAuth2\HttpFoundationBridge\Response as BridgeResponse;
class OAuth2Library implements ControllerProviderInterface
{
public function setup(Application $app)
{
$clients = array('oauthuser' => array(
'client_secret' => 'xkJ7ua2p9zaRQ78YxYAfTCKGUaGEfMS6'
));
$storage = new OAuth2MemoryStoraage(array('client_credentials' => $clients));
$server = new OAuth2Server($storage, array('issuer' => $_SERVER['HTTP_HOST']));
$server->addGrantType(new ClientCredentials($storage));
$app['oauth_server'] = $server;
$app['oauth_response'] = new BridgeResponse();
}
public function connect(Application $app)
{
$this->setup($app);
$routing = $app['controllers_factory'];
$routing->post('/accesstoken', 'App\\Controllers\\OAuthController::authorize');
return $routing;
}
}
对于给出访问 token 的函数(在另一个文件中):
namespace App\Controllers;
use OAuth2;
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
use OAuth2\HttpFoundationBridge\Request as BridgeRequest;
class OAuthController
{
public function authorize(Application $app)
{
$server = $app['oauth_server'];
$response = $app['oauth_response'];
return $server->handleTokenRequest($app['request'], $response);
//return $app->json($encoded, 200);
}
}
最后,在另一个文件中,获取资源的函数:
namespace App\Controllers;
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
use OAuth2;
class HelloController
{
public function get(Application $app)
{
$server = $app['oauth_server'];
$response = $app['oauth_response'];
if (!$server->verifyResourceRequest($app['request'], $response)) {
return $server->getResponse();
}
else
{
$result = $app['db']->fetchAssoc("select * from user");
return new Response(json_encode($result));
}
}
}
我做错了什么?谢谢!
最佳答案
OAuth2\Storage\Memory 不会在请求之间持久化,因此您需要使用数据库(例如 OAuth2\Storage\Pdo)来存储 access_tokens。
您可以将 SQLite 作为单个文件与 PDO 一起用于测试:sqlite.org/onefile.html
关于php - 仅使用 bshaffer OAuth2.0 库实现客户端凭据授权类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36791937/
我有一个 webapp,它使用 php 服务器和数据库服务器执行大量 ajax 请求。我还创建了一个 iPhone 应用程序和一个 Android 应用程序,直到现在它们一直作为离线应用程序工作。 现
OAuth 的访问 token /刷新 token 流对我来说似乎非常不安全。帮助我更好地理解它。 假设我正在与利用 OAuth 的 API 集成(如 this one )。我有我的访问 token
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: How is oauth 2 different from oauth 1 我知道这两个不向后兼容。但是,既然已经实
我已经看到关于此的其他问题( here 、 here 和 here ),但我对任何解决方案都不满意,所以我再次询问。我正在启动一个 Web 应用程序,它将利用来自多个提供商(Google、Facebo
我知道(在 OAuth 中使用授权代码“授权代码”时),访问 token 的生命周期应该很短,但刷新 token 的生命周期可能很长。 所以我决定为我的项目: 访问 token 生命周期:1 天 刷新
在没有浏览器的情况下,我们可以在手机上的应用程序中使用 OAuth 吗? 如果没有浏览器,用户是否仍然可以批准 token 请求(以便消费者可以继续从服务提供者那里获取 protected 资源)?
用非常简单的术语来说,有人可以解释一下 OAuth 2 和 OAuth 1 之间的区别吗? OAuth 1 现在已经过时了吗?我们应该实现 OAuth 2 吗?我没有看到很多 OAuth 2 的实现;
修改表单例份验证登录过程并不难,因此除了正常的表单例份验证之外,WebClient 对象对由使用 Thinktecture IdentityModel 设置的 Web Api DAL 提供的 api/
我想连接到 LinkedIn 并通过他们的 API 提取一些信息。 LinkedIn API 使用 OAuth 2.0。 我读过的所有关于 OAuth 的文档(无论是在 LinkedIn 的上下文中还
OAuth 与其他身份验证标准的支持范围有多广? 这可能是社区维基的东西,但我还是要问。 我需要投资一些与服务器身份验证相关的东西,而且那里似乎有一些不错的东西。 最佳答案 OAuth 主要用作授权机
我有几个问题... 雅虎和微软 api 是否支持 oAuth 2.0? 如果是,那么主要是什么 应该采取的安全措施 转移时受到照顾 oAuth 1.0 到 oAuth 2.0。 Google API
我已经用谷歌 oAuth 开发了一个应用程序,这工作正常。 我可以登录并访问我的网站。 我的问题是,当我从我的应用程序中注销(注销)时,我删除了所有 session ,但未删除经过身份验证的 cook
我在 Internet 上寻找一些关于此的信息,最后在 RFC 上找到了 Oauth 1.0 协议(protocol):https://www.rfc-editor.org/rfc/rfc5849 您
我正在尝试制作 Google OpenID/OAuth hybrid签到工作。问题是它是一个可安装的网络(所以没有固定域),我也试图让它在我的开发机器上工作 - 所以返回 URL 类似于 http:/
我想构建一个独立与任何身份提供者(如 ADFS、OpenAM、oracle 身份)一起工作的应用程序。我的目的是验证来自任何一个 IDP 的登录用户,这些 IDP 配置为实现我的 SSO。 我不确定
我正在深入研究 Spring OAuth,发现一些相互矛盾的信息。 具体来说,this tutorial声明 /oauth/token 端点在将刷新 token 授予客户端应用程序之前处理用户名和密码
如何通过自定义命令行工具支持三足式 OAuth 工作流? 我想允许我的 CLI 工具的用户上网、登录并在本地缓存 token ,类似于 heroku login。正在做。 最佳答案 你必须扔掉同意屏幕
什么是 oauth 域?是否有任何免费的 oauth 服务?我可以将它用于 StackApps registration 吗? ?我在谷歌上搜索了很多,但找不到答案。 最佳答案 这是redirect_
我需要将我的 Delicious 书签下载到非 Web 应用程序,而无需持续的用户交互。我正在使用 Delicious 的 V2 API(使用 oAuth),但问题是他们的访问 token 似乎在一小
我正在尝试为两台服务器设置一个 nginx 负载均衡器/代理,并在两台服务器上运行 OAuth 身份验证的应用程序。 当 nginx 在端口 80 上运行时,一切都运行良好,但是当我将它放在任何其他端
我是一名优秀的程序员,十分优秀!