在PHP应用中简化OAuth2.0身份验证集成:OAuth 2.0 Client
在PHP应用中简化OAuth2.0身份验证集成:OAuth 2.0 Client
这个包能够让你以很简单的方式在在PHP应用中集成OAuth2.0身份验证。
用法
验证代码流程
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
$provider = new League\OAuth2\Client\Provider\<ProviderName>(array( 'clientId' => 'XXXXXXXX', 'clientSecret' => 'XXXXXXXX', 'redirectUri' => 'https://your-registered-redirect-uri/', 'scopes' => array('email', '...', '...'),));if ( ! isset($_GET['code'])) { // If we don't have an authorization code then get one header('Location: '.$provider->getAuthorizationUrl()); exit;} else { // Try to get an access token (using the authorization code grant) $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); // If you are using Eventbrite you will need to add the grant_type parameter (see below) $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'], 'grant_type' => 'authorization_code' ]); // Optional: Now you have a token you can look up a users profile data try { // We got an access token, let's now get the user's details $userDetails = $provider->getUserDetails($token); // Use these details to create a new profile printf('Hello %s!', $userDetails->firstName); } catch (Exception $e) { // Failed to get user details exit('Oh dear...'); } // Use this to interact with an API on the users behalf echo $token->accessToken; // Use this to get a new access token if the old one expires echo $token->refreshToken; // Number of seconds until the access token will expire, and need refreshing echo $token->expires;} |
Refreshing a Token
|
1
2
3
4
5
6
7
8
|
$provider = new League\OAuth2\Client\Provider\<ProviderName>(array( 'clientId' => 'XXXXXXXX', 'clientSecret' => 'XXXXXXXX', 'redirectUri' => 'https://your-registered-redirect-uri/'));$grant = new \League\OAuth2\Client\Grant\RefreshToken();$token = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken]); |
Built-In Providers
这个包目前已经内置了支持:
- Eventbrite
- Github
- Microsoft
在PHP应用中简化OAuth2.0身份验证集成:OAuth 2.0 Client的更多相关文章
- WebApi 增加身份验证 (OAuth 2.0方式)
1,在Webapi项目下添加如下引用: Microsoft.AspNet.WebApi.Owin Owin Microsoft.Owin.Host.SystemWeb Microsoft.Owin.S ...
- 在ASP.NET Core 2.0中使用Facebook进行身份验证
已经很久没有更新自己的技术博客了,自从上个月末来到天津之后把家安顿好,这个月月初开始找工作,由于以前是做.NET开发的,所以找的还是.NET工作,但是天津这边大多还是针对to B(企业)进行定制开发的 ...
- MVC5个人用户账户身份验证集成google和facebook的OAuth2登陆
最终效果 官方文档:MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on 内容简介:上面传送门的博客中讲解了如何在M ...
- Angular 应用中的登陆与身份验证
Angular 经常会被用到后台和管理工具的开发,这两类都会需要对用户进行鉴权.而鉴权的第一步,就是进行身份验证.由于 Angular 是单页应用,会在一开始,就把大部分的资源加载到浏览器中,所以就更 ...
- ASP.NET站点Windows身份验证集成AD域,非LDAP
站点集成AD域验证 服务器机器入域 计算机右键属性-->“更改设置”-->“更改”-->填写所属域,确认后重启机器生效. 部署测试站点,localhost.ip.域名三种方式登录效果 ...
- MVC中使用AuthorizeAttribute做身份验证操作
代码顺序为:OnAuthorization-->AuthorizeCore-->HandleUnauthorizedRequest 如果AuthorizeCore返回false时,才会走H ...
- MVC中使用AuthorizeAttribute做身份验证操作【转】
http://blog.csdn.net/try530/article/details/7782704 代码顺序为:OnAuthorization-->AuthorizeCore-->Ha ...
- 在Laravel中使用Middleware进行身份验证
新建一个中间件: 方法写在handle中 判断用户是否登录而且是否是管理员,不是的话返回到主页 新建判断是否为管理员的方法 在kernel定义一个中间件,key是admin 注册群组路由:prefix ...
- 从零搭建一个IdentityServer——聊聊Asp.net core中的身份验证与授权
OpenIDConnect是一个身份验证服务,而Oauth2.0是一个授权框架,在前面几篇文章里通过IdentityServer4实现了基于Oauth2.0的客户端证书(Client_Credenti ...
随机推荐
- C++模板元编程 - 1 基本数据类型和运算
这是博客开通前几天做的,C++的模板没办法存方便的浮点数,算了. 基本类型的设计参考了vczh轮子叔模仿boost的MPL的设计. 话说template和typename写多了真是无限烦人啊,不得已定 ...
- studio--问题
2,Android studio 怎么能删除干净一个module? 工程→open module settings→选中你要删除的module,然后点“一”,确定后返回,即可在module邮件下看到d ...
- 转载__Android-屏幕适配需要注意的地方
1.尽量使用线性布局(LinearLayout)和相对布局(RelativeLayout),不要使用绝对布局. 2.尽量使用dip和sp,不要使用px. 3.为不同的分辨率提供不同的布局文件和图片. ...
- Maven如何手动添加依赖的jar文件到本地Maven仓库
大家肯定遇到过想在pom文件中加入自己开发的依赖包,这些包肯定是不是在Maven仓库(http://repo1.maven.org/maven2/)的.那我们怎么将那些不存在Maven仓库中的包加入到 ...
- SQL Server 2008 建立分区表 脚本
/*第一步:创建分区函数*/Create partition function Part_func_Bag(varchar(20)) as range right /*正式区间for values(N ...
- Python中作Q-Q图(quantile-quantile Plot)
Q-Q图主要可以用来回答这些问题: 两组数据是否来自同一分布 PS:当然也可以用KS检验,利用python中scipy.stats.ks_2samp函数可以获得差值KS statistic和P值从而实 ...
- Linux备份入门:3种克隆方法详解_Clonezilla
摘自:http://os.51cto.com/art/201006/206871.htm 给你的系统磁盘制作一个镜像拷贝是创建备份的好办法.由于便携式U盘总是有比较低廉的价格,你可以维护数个拷贝以便循 ...
- CentOS7 备忘录
//安装CentOS7 1.用LinuxLive USB Creator,LiveUSB Creator设置U盘安装不成功,UltraISO可以. 2.旧电脑(x8le)安装时报"/dev/ ...
- java记录在线人数小案例
文件目录: web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...
- 使用go tool pprof分析内存泄漏、CPU消耗
go中提供了pprof包来做代码的性能监控,在两个地方有包: net/http/pprof runtime/pprof 其实net/http/pprof中只是使用runtime/pprof包来进行封装 ...