oauth2 demo php,OAuth2 Demo PHP

OAuth2 Demo PHP

此应用程序的目的是演示OAuth2.0客户端和服务器之间的工作流。

如果这是你第一次来这里,试图尝试的现场演示让OAuth2.0流更好的感觉。

这个图书馆是oauth2服务器运行PHP库。

安装

使用 Composer 安装这个应用程序:

$ git clone git://github.com/bshaffer/oauth2-demo-php.git

$ cd oauth2-demo-php

$ curl-s http://getcomposer.org/installer | php

$ ./composer.phar install

WebHost Configuration

高手写的配置

配置一个Web服务器

Silex requires you to configure your web server to run it.

Be sure to run the command $ chmod -R 777 data/ in the project root so that the web server can create the sqlite file.

使用PHP的内置Web服务器

您可以使用php的内置的web服务器然而,您将需要旋转两个实例,指定其中的一个数据/ parameters.json为了防止服务器锁定。 客户端向服务器发出请求,因为PHP的内置web服务器是单线程的,这将导致死锁。

$ cd oauth2-demo-php

$ cp data/parameters.json.dist data/parameters.json

$ sed-i '' 's?"grant"?"http://localhost:8081/lockdin/token"?g' data/parameters.json

$ sed-i '' 's?"access"?"http://localhost:8081/lockdin/resource"?g' data/parameters.json

现在你要做的就是自旋向上两个单独的web服务器web目录

$ cd web

$ php-S localhost:8080 & php -S localhost:8081

浏览到http://localhost:8080在您的浏览器中,你都准备好了!

这个程序是做什么的? ?

这个应用程序模拟之间的交互OAuth2客户机(演示应用程序)和OAuth2服务器(锁)。 首先,访问演示应用程序的主页:

b9d6be67b4e31f2fea809207f8d177f7.png

点击授权  Authorize将你锁会,模拟数据提供商(如twitter、facebook等)。 锁会在假定您已经签署,并要求如果你想演示应用程序授予访问您的信息:

d30e788434a2d954e328fdd0cede26f4.png

一旦你点击是的,我批准这个请求,您将被重定向回和一个演示应用程序授权代码,这然后客户端交流the client then exchanges 对于一个访问令牌。 演示应用程序然后让另一个调用锁会在api和使用访问令牌代表你检索数据。

如果成功,您的数据从锁在最后一页将显示:

95c9f34f32ec3b7b77c29751d3d655b5.png

OAuth2客户端可以用来测试任何OAuth2.0服务器,可以配置为使用配置文件定义下面。

OAuth2服务器

OAuth2服务器创建(见设置方法),然后使用控制器类以下哪一个端点实现:

/授权 authorize——授予演示应用程序一个端点授权代码

/令牌 token——授予演示应用程序一个端点access_token当提供上述授权代码

/资源 resource——端点赠款演示应用程序访问受保护的资源(在这种情况下,你的朋友)当提供上面的访问令牌

这三个OAuth2服务器的主要功能(授权用户,授予用户令牌,并验证api调用)。 当你写OAuth2-compatible服务器,你的界面会是相似的。

注:以上url前缀/服务器名称空间的应用程序。

Note: the above urls are prefixed with /server to namespace the application.  注:以上url前缀/服务器名称空间的应用程序。

Test Your Own OAuth2 Server!

测试自己的OAuth2服务器!

您可以测试这个应用程序轻松地对自己的OAuth应用程序。 复制的parameters.json.dist文件 parameters.json:

$ cd /path/to/oauth2-demo-php

$ cp data/parameters.json.dist data/parameters.json

打开参数。 json文件,注意默认配置:

{

"client_id": "demoapp",

"client_secret": "demopass",

"token_route": "grant",

"authorize_route": "authorize",

"resource_route": "access",

"resource_method": "GET",

"resource_params": {},

"curl_options": {}

}

这是默认的配置就锁在OAuth2服务器。 对自己的测试,改变这些参数以适应api服务器你想测试:

{

"client_id": "OAuth Demo Application",

"client_secret": "a3b4b74330724a927bec",

"token_route": "https://api.myapp.com/token",

"authorize_route": "https://myapp.com/authorize",

"resource_route": "https://api.myapp.com/profile",

"resource_method": "POST",

"resource_params": { "debug": true },

"curl_options": { "http_port": 443, "verifyssl": false }

}

上面的例子使用了一个新客户对一个虚构的oauth身份验证服务器myapp.com。 这是测试您的应用程序在生产时非常有用

Note: The curl options are set to ignore an SSL certificate, and the resource_params define a fictional debug parameter. These are not required for your APIs, but is meant as an example what can be done with the configuration

注:卷曲的选项设置忽略SSL证书,和resource_params定义一个虚构的调试参数。这些不是您的API所必需的,但也可以作为配置的一个例子。

###Test多环境测试

此外,您可以使用 parameters.json 文件创建多个环境,和它们之间的切换:

{

"LockdIn": {

"client_id": "demoapp",

"client_secret": "demopass",

"token_route": "grant",

"authorize_route": "authorize",

"resource_route": "access",

"resource_method": "GET",

"resource_params": {},

"curl_options": {}

},

"My App": {

"client_id": "OAuth Demo Application",

"client_secret": "a3b4b74330724a927bec",

"token_route": "https://api.myapp.com/token",

"authorize_route": "https://myapp.com/authorize",

"resource_route": "https://api.myapp.com/profile",

"resource_method": "POST",

"resource_params": { "debug": true },

"curl_options": { "http_port": 443, "verifyssl": false }

}

}

这将在顶部,这将允许你切换环境和测试多个OAuth服务器提供一个下拉

40bd2d3b2aca4d52e5ffd3d5dd0e75cd.png

Contact

Please contact Brent Shaffer (77811970 qq com) for more information

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值