首页 技术 正文
技术 2022年11月12日
0 收藏 962 点赞 3,414 浏览 2083 个字

在PHP应用中简化OAuth2.0身份验证集成:OAuth 2.0 Client

 

阅读目录

这个包能够让你以很简单的方式在在PHP应用中集成OAuth2.0身份验证。
用法

验证代码流程

?

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 $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

?

12345678 $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
  • Facebook
  • Github
  • Google
  • Instagram
  • LinkedIn
  • Microsoft

项目主页:http://www.open-open.com/lib/view/home/1417502997514

上一篇: psutil
下一篇: facelets标签
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,492
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294