在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 ...
随机推荐
- HDU 3709 Balanced Number (数位DP)
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- [DNS] 网页无法打开,设置合适的DNS解决问题
一.缘由: 家里装的10M长城宽带,下载速度很快,就是打开网页会经常失败.播放视频会卡无法播放:最近尤甚,甚是恼怒. 在画个圈圈诅咒长城宽带的同时,突然想起来打不开网页很大可能是DNS解析失败导致,故 ...
- vim 学习日志(3):跳到行尾、行首、文件尾、文件首、加密
vi操作: 1.跳到文本的最后一行:按“G”,即“shift+g” 2.跳到最后一行的最后一个字符 : 先重复1的操作即按“G”,之后按“$”键,即“shift+4”. 3.跳到第一行的第一个字符:先 ...
- Enumerator yielder.yield 与 Proc.yield 区别
最近看ruby cookbook遇到这个用法,google一下,这里原文解释 http://stackoverflow.com/questions/18865860/enumerator-yielde ...
- C#导出带有格式的Excel(列宽,合并单元格,显示边框线,加背景颜色等)
源地址:http://blog.sina.com.cn/s/blog_74f702e60101au55.html 导出excel相关设置:http://blog.csdn.net/wanmingtom ...
- ubuntu入门知识
1.linux系统发展历史 unix -> Linux -> ubuntu linux发展轨迹图 2.ubuntu下载和安装 推荐使用长期支持版本: 10.04,12.04,14.04或L ...
- [ActionScript 3.0] 跨域策略文件crossdomain.xml配置详解
1.简介 flash在跨域时唯一的限制策略就是crossdomain.xml文件,该文件限制了flash是否可以跨域读写数据以及允许从什么地方跨域读写数据. 位于www.a.com域中的SWF文件要访 ...
- testng.xml创建及解析
项目右键---TestNG -----> Convert to TestNG 会自动产生一个testng.xml的文件 http://www.cnblogs.com/choosewang/art ...
- 单元测试利器之Jtester
http://kiral.iteye.com/blog/900975 名词解释: Junit:众所周知的单元测试. 官方网址:http://junit.sourceforge.net/.Junit从4 ...
- java代码中后台向前台传递list或map集合案例
导入jar包 新建一个servert传递map集合 ajax.java代码: package servlet; import java.io.IOException; import java.io.P ...