layerhq/layer-identity-token-php
最新稳定版本:1.0.0
Composer 安装命令:
composer require layerhq/layer-identity-token-php
包简介
Layer PHP Identity Token Provider
README 文档
README
The code in this folder provides a PHP library for generating a Layer Identity Token. The PHP library supports php 5.4+.
Available on Packagist.
Installation
Add Layer Identity Token Provider to your project using Composer
cd <your_project> composer require layerhq/layer-identity-token-php composer update
Initial Setup
There are 3 environment variables you need to set up before using the code:
LAYER_PROVIDER_ID- Provider ID found in the Layer DashboardLAYER_PRIVATE_KEY_ID- Public key generated and stored in the Layer DashboardLAYER_PRIVATE_KEY- Contents of private key associated with the public key
All of these values are available in the Keys section of the Layer dashboard for your app. You can also manually set these values in the library (see details below).
Usage
$layerIdentityTokenProvider = new \Layer\LayerIdentityTokenProvider(); $identityToken = $layerIdentityTokenProvider->generateIdentityToken(USER_ID, NONCE);
The generateIdentityToken method requires 2 parameters:
USER_ID: The user ID of the user you want to authenticate.NONCE: The nonce you receive from Layer. See docs for more info.
By default, LayerIdentityTokenProvider will look at the LAYER_PROVIDER_ID, LAYER_PRIVATE_KEY_ID, and LAYER_PRIVATE_KEY environment variables for credentials. You can overwrite those values by uncommenting the following lines and replacing their values
$layerIdentityTokenProvider->setProviderID("layer:///providers/..."); $layerIdentityTokenProvider->setKeyID("layer:///keys/..."); $layerIdentityTokenProvider->setPrivateKey("----BEGIN RSA PRIVATE KEY....");
Running the sample
The composer package includes a sample inside the public folder. This sample can be easily deployed to Heroku.
Then send an example request to the server containing authenticate.php:
curl \ -D - \ -X POST \ -d "nonce=NONCE" -d "user_id=USER_ID" \ http://YOUR_SERVER/authenticate.php``` Upon success, the endpoint will return a JSON object that contains a single key, `identity_token`. If the required input parameters were not provided, the endpoint will respond with "Invalid response." Example successful response: ```console HTTP/1.1 200 OK Date: Thu, 13 Aug 2015 06:18:56 GMT Server: Apache/2.4.10 (Unix) PHP/5.5.24 X-Powered-By: PHP/5.5.24 Content-Length: 519 Content-Type: text/html {"identity_token":"..SNIP.."}
Verify
You should verify the output of the signing request by visiting the Tools section of the Layer dashboard.
Paste the value of the identity_token key you received from the output above and click validate. You should see "Token valid".
Deploying Sample to Heroku
Automated Install
Manual Install
You can easily deploy the php code to Heroku.
Install the Heroku Toolbelt to start, then follow their 'Getting Started' instructions, including logging in the first time:
% heroku login
Enter your Heroku credentials.
Email: youremail@example.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /Users/you/.ssh/id_rsa.pub
Inside your new directory, make sure you've created a git repository, and that your work is committed:
% git init
% git add .
% git commit -m "Initial commit"
Then create a Heroku application:
% heroku create
Creating young-waterfall-2641... done, stack is cedar
http://young-waterfall-2641.herokuapp.com/ | git@heroku.com:young-waterfall-2641.git
Git remote heroku added
Before you deploy the application, you'll need to configure some environment variables for the server to use. You can get these values from the Layer Dashboard under Authentication:
% heroku config:set LAYER_PROVIDER_ID=yourlayerproviderid
% heroku config:set LAYER_PRIVATE_KEY_ID=yourlayerkeyid
This code will look for the private key inside a file layer-key.pem. You will get the private key when you generate a Authentication key in the dashboard. You can optionally add the private key as a environment variable:
% heroku config:set LAYER_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----"
At this point, you are ready to deploy and start chatting. With Heroku, that's a git push away:
% git push heroku master
You'll see some text flying, and eventually some success. You should now be ready to test the code. If the server returns an error you can peek at the logs to try to debug:
% heroku logs
If you make any changes to your code, just commit and push them as before:
% git commit -am "Updating server code"
% git push heroku master
layerhq/layer-identity-token-php 适用场景与选型建议
layerhq/layer-identity-token-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 92.86k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「layer」 「jwt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 layerhq/layer-identity-token-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 layerhq/layer-identity-token-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 layerhq/layer-identity-token-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
ADOdb is a PHP database abstraction layer library
A simple library to decode and parse Apple Sign In client tokens.
JWT API authentication driver (Guard) for Laravel.
Laravel JWT auth service package
A Laravel 6 API Boilerplate to create a ready-to-use REST API. User Authentication using JWT.
VV database abstraction layer with query builder and DB structure models
统计信息
- 总下载量: 92.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2015-08-26