PHPackages                             jwelmac/bit6-token-generator-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. jwelmac/bit6-token-generator-php

ActiveLibrary

jwelmac/bit6-token-generator-php
================================

Token generator for Bit6 external authentication

06PHP

Since Jan 2Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jwelmac/bit6-token-generator-php)[ Packagist](https://packagist.org/packages/jwelmac/bit6-token-generator-php)[ RSS](/packages/jwelmac-bit6-token-generator-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Bit6 Token Generator for PHP [![Build Status](https://camo.githubusercontent.com/3f7673bef44925a8573b1e9ef83130d6f21fb2dd8aa3b5819c8db7feedf3bb70/68747470733a2f2f7472617669732d63692e6f72672f6a77656c6d61632f626974362d746f6b656e2d67656e657261746f722d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jwelmac/bit6-token-generator-php)
============================================================================================================================================================================================================================================================================================================================================================

[](#bit6-token-generator-for-php-)

A PHP package demonstrating the use of delegated authentication in Bit6.

Prerequisites
-------------

[](#prerequisites)

- Get the API Key and Secret at [Bit6 Dashboard](https://dashboard.bit6.com).

Install via Composer
--------------------

[](#install-via-composer)

To incorporate into your current project simply run:

```
$ composer.phar require bit6/bit6-token-generator-php
```

### Generating Tokens

[](#generating-tokens)

- Create token generator:

```
// Ideally pull variables by parsing ini file or from env
$apiKey = 'API_KEY';
$apiSecret = 'API_SECRET';

// Create new TokenGenerator
$bit6_tg = new Bit6\TokenGenerator($apiKey, $apiSecret);
```

- Get identities from your app following internal authentication.
- Generate token using one of the following options:

*Option 1: Using a string to represent an identity URI*

```
$identities = "mailto:user@test.com";

// Generate token
$token = $bit6_tg->createToken($identities);
```

*Option 2: Using an indexed array of identity URIs*

```
$identities = array("usr:john123", "tel:12345678901");

// Generate token
$token = $bit6_tg->createToken($identities);
```

*Option 3: Using an associative array of options*

```
$options = array(
  "identities" => array("usr:john123", "mailto:user@test.com"),
  "issued" => 1468709885,
  "expires" => 1468796285
);

// Generate token
$token = $bit6_tg->createToken($options);
```

### Create Token Options

[](#create-token-options)

The `createToken` method can be called with an associative array with the following keys:

- `identities` (required) - A string or array of strings of identity URIs as shown below. When an array is used the first value becomes the primary identity.

  Protocol Data (RegEx) Type Example   usr /^\[a-z0-9.\]+$/ User usr:john123   grp /\[0-9a-zA-Z.\_\]{22}/ Group ID grp:9de82b5b\_236d\_40f6\_b5a2   mailto /^\[a-z0-9.\_%+-\]+@\[a-z0-9.-\]+\\.\[a-z\]{2,8}$/ Email Address mailto:test@user.com   tel /^\\+\[1-9\]{1}\[0-9\]{8,15}$/ Telephone Number tel:12345678901   uid /\[0-9a-f\]{8}-\[0-9a-f\]{4}-\[0-9a-f\]{4}-\[0-9a-f\]{4}-\[0-9a-f\]{12}/ Unique ID uid:9de82b5b-236d-40f6-b5a2-e16f5d09651d - `issued` (optional) - The unix timestamp at which token was generated (default - current system time)
- `expires` (optional) - The unix timestamp at which the token will expire (default - 10 minutes from time of creation)

### Authentication

[](#authentication)

Pass the token to browser using your preferred method eg. via JSON response, url or inline-script.

Authenticate user in javascript (after loading bit6.min.js) as shown below:

```
  // Authenticate with external token
  b6.session.external(token, function(err) {
    if (err) {
      // Houston we have a problem!
      console.log('Token login error', err);
    }
    else {
      // Code to run post authentication
      console.log('Token login successful');
    }
  });

```

Using example code
------------------

[](#using-example-code)

### Running Locally

[](#running-locally)

```
$ git clone git@github.com:bit6/bit6-token-generator-php.git
$ cd bit6-token-generator-php
$ composer update
```

Specify your Bit6 API key and secret using environment variables or a local `.env` config file. The file should contain two lines:

```
BIT6_API_KEY=abc
BIT6_API_SECRET=xyz

```

Start the application

```
$ php -S localhost:5000 -t example/
# Alternatively run:
# heroku local
```

Your app should now be running on [localhost:5000](http://localhost:5000/).

### Deploying to Heroku

[](#deploying-to-heroku)

Make sure you have the [Heroku Toolbelt](https://toolbelt.heroku.com/) installed.

```
$ heroku create
$ git push heroku master
```

or

[![Deploy to Heroku](https://camo.githubusercontent.com/3da7ea007288c7a8b14c8c84f0836d66ba8f82bd2f3b72fb7e0e72e19a16d28f/68747470733a2f2f7777772e6865726f6b7563646e2e636f6d2f6465706c6f792f627574746f6e2e706e67)](https://heroku.com/deploy)

Set Bit6 API key and secret:

```
$ heroku config:set BIT6_API_KEY=abc
$ heroku config:set BIT6_API_SECRET=xyz
```

### Generating a Token

[](#generating-a-token)

You would normally generate an external token by doing a POST from your app client to your application server. To simulate this using `curl`:

```
curl -X POST \
    -H "Content-Type: application/json" \
    -d '{"identities": ["usr:john","tel:+12123331234"]}' \
    http://localhost:5000/auth.php
```

The response should be a JSON object:

```
{
    "ext_token": "..."
}
```

### Documentation

[](#documentation)

For more information about using PHP on Heroku, see these Dev Center articles:

- [Getting Started with PHP on Heroku](https://devcenter.heroku.com/articles/getting-started-with-php)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a46f91e21f259ad4aeb34a82949cb70c1d8dfcb710f847aab5a9752f3d387ef?d=identicon)[jwelmac](/maintainers/jwelmac)

---

Top Contributors

[![jwelmac](https://avatars.githubusercontent.com/u/4424342?v=4)](https://github.com/jwelmac "jwelmac (5 commits)")[![agol](https://avatars.githubusercontent.com/u/1692843?v=4)](https://github.com/agol "agol (3 commits)")

### Embed Badge

![Health badge](/badges/jwelmac-bit6-token-generator-php/health.svg)

```
[![Health](https://phpackages.com/badges/jwelmac-bit6-token-generator-php/health.svg)](https://phpackages.com/packages/jwelmac-bit6-token-generator-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
