etalio / php-sdk
此包已被废弃,不再维护。未建议替代包。
Etalio PHP SDK
0.4.11
2015-02-23 16:26 UTC
Requires
- php: >=5.2.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: 3.7.*
README
入门
这假设您已经在 开发者门户 上创建了 Etalio 应用程序
查看 PHP 入门指南以开始。
应用程序密钥
请确保您从密钥注册中获得了以下内容
- 客户端 ID
- 客户端密钥
- 重定向 URI
密钥看起来像这样
Application : Test Application
KeyName : My first key
ClientId : d0d7ef3c-0807-4b0b-8354-22537dc21c40
Client secret : 6b527f6b-2df0-4104-a322-1704b690cd75
Scopes :
scope.r
scope.w
Redirects :
http://example.com/auth/etalio/callback
https:///auth/etalio/callback
配置
将此片段添加到您的项目中,并用密钥的值替换
require_once('etalio_with_session_store.php'); $etalio = new \Etalio\EtalioWithSessionStore([ 'appId' => "<your client_id>", 'secret' => "<your client secret>", 'redirect_uri' => "<the redirect back to your site>", 'debug' => false // Optional but useful when debugging the calls back to the etalio api ]);
认证
当您想认证用户时,将他们重定向到从访问获取的 Etalio 登录和注册 URL
$etalio->getLoginUrl([ 'scope' => 'scope.r scope.w', // The scopes for your application 'acr_values' => '2', // 2 => Single factor authentication, 3 => 2 factor authentication 'prompt' => '', // login => user needs to re-authenticate, consent => user needs to accept your scopes again, none => the user will not be presented with a UI. If authentication fails an error message will be produced., '' => default behaviour ])
这将重定向用户到 Etalio OAuth2 同意页面。用户批准或拒绝您的应用程序后,它将重定向回您在创建密钥时定义的重定向 URI。在重定向请求中运行 authenticateUser()
函数。
$etalio->authenticateUser();
此方法将在 $_request
对象中查找认证头,并处理对 Etalio 的回调,以将重定向中的 OAuth2 代码头与您的客户端密钥交换为认证令牌和刷新令牌。
在下一次请求中,您可以调用
$etalio->isAuthenticated();
API
如果您想了解更多关于用户的信息,例如他们的姓名,请调用
$etalio->getUserinfo();
响应将类似于这个。
{ "id": "dde9536c-2ca2-4fdc-a710-17ef0a58ede8", "msisdn": { "country_code": 386, "number": "+38640123456" }, "email": { "address": "email@example.com", "authenticated": true }, "name": "Profile Name", "verified": true, "links": [{ "rel": "my-apps", "href": "https://api.etalio.com/v1/profile/me/applications" }] }
许可证
版权 2014 爱立信 AB
根据 Apache 许可证版本 2.0(“许可证”)授权;除非适用法律要求或书面同意,否则不得使用此文件,除非符合许可证。您可以在以下位置获取许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则根据许可证分发的软件按“原样”提供,不提供任何明示或暗示的保证或条件。有关许可证的具体语言、权限和限制,请参阅许可证。