承接 nathanfeitoza/firebase-tokens-php-5.6 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nathanfeitoza/firebase-tokens-php-5.6

最新稳定版本:1.9.1

Composer 安装命令:

composer require nathanfeitoza/firebase-tokens-php-5.6

包简介

A library to work with Firebase tokens

README 文档

README

A library to work with Google Firebase tokens. You can use it to create custom tokens and verify ID Tokens.

Achieve more with the Firebase Admin SDK for PHP 5.6 (which uses this library).

Current version Supported PHP version Monthly Downloads Total Downloads

Build Status

Installation

composer require nathanfeitoza/firebase-tokens-php-5.6

Simple usage

Create a custom token

<?php

use Kreait\Firebase\JWT\CustomTokenGenerator;

$clientEmail = '...';
$privateKey = '...';

$generator = CustomTokenGenerator::withClientEmailAndPrivateKey($clientEmail, $privateKey);
$token = $generator->createCustomToken('uid', ['first_claim' => 'first_value' /* ... */]);

echo $token;
// Output: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.e...

Verify an ID token

<?php

use Kreait\Firebase\JWT\Error\IdTokenVerificationFailed;
use Kreait\Firebase\JWT\IdTokenVerifier;

$projectId = '...';
$idToken = '...';

$verifier = IdTokenVerifier::createWithProjectId($projectId);

try {
    $token = $verifier->verifyIdToken($idToken);
} catch (IdTokenVerificationFailed $e) {
    echo $e->getMessage();
    // Example Output:
    // The value 'eyJhbGciOiJSUzI...' is not a verified ID token:
    // - The token is expired.
    exit;
}

try {
    $token = $verifier->verifyIdTokenWithLeeway($idToken, $leewayInSeconds = 10000000);
} catch (IdTokenVerificationFailed $e) {
    print $e->getMessage();
    exit;
}

Tokens

Tokens returned from the Generator and Verifier are instances of Kreait\Firebase\JWT\Token.

$tokenHeaders = $token->getHeaders(); // array
$tokenPayload = token->getPayload(); // array
$tokenString = $token->toString();
$tokenString = (string) $token;

Advanced usage

Cache results from the Google Secure Token Store

In order to verify ID tokens, the verifier makes a call to fetch Firebase's currently available public keys. The keys are cached in memory by default.

If you want to cache the public keys more effectively, you can use an implementation of psr/simple-cache or psr/cache to wrap the

Example using the Symfony Cache Component

use Kreait\Firebase\JWT\IdTokenVerifier;
use Symfony\Component\Cache\Simple\FilesystemCache;

$cache = new FilesystemCache();

$verifier = IdTokenVerifier::createWithProjectIdAndCache($projectId, $cache);

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 4.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 34
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-11