Download the PHP package oire/osst without Composer

On this page you can find all versions of the php package oire/osst. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package osst

Osst, Simple Yet Secure Tokens Suitable for Authentication Cookies and Password Recovery

Note! This library is not maintained anymore.

Please use Iridium security library instead.

Latest Version on Packagist MIT License

Welcome to Osst, Oirë Simple Split Tokens!
This library can be used for generating and validating secure tokens suitable for authentication cookies, password recovery and various other tasks.
Depends on Oirë Base64 for encoding binary data and Oirë Colloportus for encrypting data that need to be decrypted in future.

The Split Tokens Concept

You can read everything about the split tokens authentication in this 2017 article by Paragon Initiatives. This library implements the idea outlined in that article in PHP.

Requirements

Requires PHP 7.3 or later with MbString and OpenSSL enabled.

Installation

Install via Composer:

Running Tests

Run ./vendor/bin/phpunit in the project directory.

Usage Examples

Osst uses fluent interface, i.e., all necessary methods can be chained.
Each time you instantiate a new Osst object, you need to provide a database connection as a PDO instance. If you don’t use PDO yet, consider using it, it’s convenient. If you use an ORM, you most likely have a getPdo() or a similar method.
Support for popular ORMs is planned for a future version.

Create a Table

Osst tries to be as database agnostic as possible (MySQL and SQLite were tested, the latter actually powers the unit tests).
First you need to create the osst_tokens table. For mySQL the statement is as follows:

You may need to adjust the syntax to suit your particular database driver (see for example the SQLite statement in the tests), as well as the name of your users table.
The field lengths are optimal, the only one you may need to adjust is additional_info, if you are planning to use it for larger sets of data.

Create a Token

first you need to create a token. There are some required properties (marked in bold) and some optional ones (marked in italic) you can set. If you don’t set one or more of the required properties, an OsstException will be thrown.

To create a token for user with ID of 123 and with token type of 3 expiring in an hour, and store it into the database, do the following:

Use $osst->getToken() to actually get the newly created token as a string.

Set and Validate a User-Provided Token

If you received an Osst token from the user, you also need to instantiate Osst and validate the token. You don't need to set all the properties as their values are taken from the database.

Note! An expired token is considered settable, i.e., not valid per se but correct, so no exception is thrown in this case, you have to check it manually as shown above. If this behavior is non-intuitive or inconvenient, please create a Github issue.

Invalidate a Token

After a token is used once (or compromised), you must invalidate it. There are two ways of invalidating a token:

Clear Expired Tokens

From time to time you will need to delete all expired tokens from the database to reduce the table size and search times. There is a method to do this. It is static, so you have to provide your PDO instance as its parameter. It returns the number of tokens deleted from the database.

Three Ways of Setting Expiration Time

You may set expiration time in three different ways, as you like:

Notes on Expiration Times

Encrypt Additional Information

You may store some sensitive data in the additional information for the token such as old and new e-mail address and similar things.
Note! Do not store passwords in this property, it can be decrypted! Passwords must not be decryptable, they must be hashed instead. If you need to handle passwords, use Oirë Colloportus, a library suitable for proper password hashing. You may store password hashes in this property, though.
If your additional info contains sensitive data, you can encrypt it. To do this, you first need to have a key created by the Colloportus library.
Colloportus gets installed with Osst, so you don't need to add anything to your composer.json file, just do the following:

That's it. I.e., if the second parameter of setAdditionalInfo() is not empty and is a valid Colloportus key, your additional information will be encrypted. If something is wrong, an OsstException will be thrown.
If you received a user-provided token whose additional info is encrypted, pass the key as the second parameter to the setToken() method.

Error Handling

Osst throws two types of exceptions:

Methods

Below all of the Osst methods are outlined.

Contributing

All contributions are welcome. Please fork, make a feature branch, hack on the code, run tests, push your branch and send a pull request.

License

Copyright © 2020-2021, Andre Polykanine also known as Menelion Elensúlë, The Magical Kingdom of Oirë.
This software is licensed under an MIT license.


All versions of osst with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
oire/base64 Version ^2
oire/colloportus Version ^2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package oire/osst contains the following files

Loading the files please wait ....