OAuth 2.0 示例身份验证服务器 [英] OAuth 2.0 Example Auth Server

查看:83
本文介绍了OAuth 2.0 示例身份验证服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试使用此 OAuth2-Server 示例 ( https://github.com/alexbilbie/oauth2-example-auth-server ) 但是当我想运行它时出现错误 <代码>致命错误:在第 2 行的/var/www/oauth2-auth-server/model_client.php 中找不到接口‘OAuth2\Storage\ClientInterface’"

I want to try with this OAuth2-Server Example ( https://github.com/alexbilbie/oauth2-example-auth-server ) but when I want to run it gives me error " Fatal error: Interface 'OAuth2\Storage\ClientInterface' not found in /var/www/oauth2-auth-server/model_client.php on line 2 "

我想我需要将 autoloader 添加到 composer.json 我做到了,但它永远给了我这个错误.但我也认为在 oauth.php 中我发现了这一行:

I think I need to add autoloader to composer.json I did it but forever it gives me this error. But I also think in oauth.php I found this line:

// Initiate the auth server with the models
$server = new \OAuth2\AuthServer(new ClientModel, new SessionModel, new ScopeModel);

但是OAuth文件夹中没有任何AuthServer?有没有人用过这个例子.提前致谢!

But there is no any AuthServer in the OAuth folder? Is there anybody used this example. Thanks in advance!

推荐答案

自动加载是使用 Composer 自动完成的,假设您已经从 composer 的 require 键中声明的模块下载了依赖项.json 文件.只需将其包含在 PHP 脚本的顶部即可访问类:

Autoloading is done automatically using Composer assuming you've downloaded the dependencies from modules stated in the require key of your composer.json file. Just include this at the top of your PHP script to access the Classes:

require_once __DIR__.'/to/vendor/autoload.php';

如果这些是手动下载的包,您需要将自动加载器指向它们并运行 composer update:

If these are manually downloaded packages you'll need to point the autoloader to them and run composer update:

"autoload": {
    "psr-0": {
      "Util\\": "assets/"
  },
  "files": ["assets/Util/init.php"]
}

以上自动:

  • assets/Util/init.php 中的脚本附加到运行自动加载器的每个文件中;
  • 并在本例中将类从 Util 命名空间(必须位于名为 Util 的文件夹中以满足 psr-0 约定,因此实际上位于 assets/Util/ 中)到任何文件中运行自动加载器
  • appends the script at assets/Util/init.php to every file where the autoloader is run;
  • and autoloads classes from, in this example, the Util namespace (has to be in a folder called Util to meet psr-0 convention so is actually at assets/Util/) into any file that runs the autoloader

您可能还需要使用 use Namespace\Class as Class; 语法来管理命名空间问题.

You may also need to manage namespace issues using the use Namespace\Class as Class; syntax.

这篇关于OAuth 2.0 示例身份验证服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆