monkdev/monk-id

Integrate Monk ID authentication and single sign-on for apps and websites on the server-side.

v1.1.0 2017-01-11 15:36 UTC

This package is auto-updated.

Last update: 2021-04-07 07:48:55 UTC


README

Latest Stable Version Build Status codecov Dependency Status

Integrate Monk ID authentication and single sign-on for apps and websites on the server-side.

Overview

Install

Using Composer, add monkdev/monk-id to your composer.json:

{
  "require": {
    "monkdev/monk-id": "~1.0"
  }
}
$ composer update

Or:

$ composer require monkdev/monk-id:~1.0

Configure

Configuration is done in an external INI file. There's a sample file in this repository: config/monkId.sample.yml. Copy this file to your codebase, then load the config in your code during initialization:

Monk\Id::loadConfig('/path/to/monkId.ini', 'development');

Remember, replace the sample values with your own, and keep the file safe as it contains your app secret.

Access

If you have Monk ID JS configured to store the payload automatically in a cookie (the default), you can skip the next part as the cookie is also loaded automatically.

If not, the encoded payload can be passed directly, which is useful if you're sending it in a GET/POST request instead:

Monk\Id::loadPayload($monkIdPayload);

Loading the payload must be done before trying to access any values stored in the payload. In an MVC framework, this usually means placing it in a method in your ApplicationController that's executed before the specific action is processed.

Once the payload is loaded, you can ask whether the user is logged in:

Monk\Id::loggedIn()

Or for their ID and email:

Monk\Id::userId()
Monk\Id::userEmail()

null is returned if the user isn't logged in or the payload can't be decoded and verified.

Development

Composer is used for dependency management and task running. Start by installing the dependencies:

$ composer install

Tests

Testing is done with PHPUnit. To run the tests:

$ composer test

Continuous integration is setup through Travis CI to run the tests against PHP v5.6, v7.0, and v7.1. (Circle CI is also setup to run the tests against PHP v5.6, but is backup for now until multiple versions can easily be specified.) The code coverage results are sent to Codecov during CI for tracking over time. Badges for both are dispayed at the top of this README.

While the test suite is complete, it's not a bad idea to also test changes manually in real-world integrations.

Documentation

phpDocumentor is used for code documentation. To build:

$ composer phpdoc

This creates a doc directory (that is ignored by git).

Quality

A number of code quality tools are configured to aid in development. To run them all at once:

$ composer quality

Each tool can also be run individually:

Deployment

Publishing a release to Packagist simply requires creating a git tag:

$ git tag -a vMAJOR.MINOR.PATCH -m "Version MAJOR.MINOR.PATCH"
$ git push origin vMAJOR.MINOR.PATCH

Be sure to choose the correct version by following Semantic Versioning.

Publish Documentation

After releasing a new version, the documentation must be manually built and published to the gh-pages branch.