Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/danielburger1337/openid-hash-php

Create/Verify OpenID Connect (OIDC) verification hashes.
https://github.com/danielburger1337/openid-hash-php

hash oidc openid openid-connect

Last synced: 14 days ago
JSON representation

Create/Verify OpenID Connect (OIDC) verification hashes.

Awesome Lists containing this project

README

        

[![PHPCSFixer](https://github.com/danielburger1337/openid-hash-php/actions/workflows/phpcsfixer.yml/badge.svg)](https://github.com/danielburger1337/openid-hash-php/actions/workflows/phpcsfixer.yml)
[![PHPStan](https://github.com/danielburger1337/openid-hash-php/actions/workflows/phpstan.yml/badge.svg)](https://github.com/danielburger1337/openid-hash-php/actions/workflows/phpstan.yml)
[![PHPUnit](https://github.com/danielburger1337/openid-hash-php/actions/workflows/phpunit.yml/badge.svg)](https://github.com/danielburger1337/openid-hash-php/actions/workflows/phpunit.yml)
![Packagist Version](https://img.shields.io/packagist/v/danielburger1337/openid-hash?link=https%3A%2F%2Fpackagist.org%2Fpackages%2Fdanielburger1337%2Fopenid-hash)
![Packagist Downloads](https://img.shields.io/packagist/dt/danielburger1337/openid-hash?link=https%3A%2F%2Fpackagist.org%2Fpackages%2Fdanielburger1337%2Fopenid-hash)

# openid-hash

Create and/or verify OpenID Connect 1.0 ID Token hashes (`at_hash`, `c_hash`, `s_hash`).

This library is [PSR-4](https://www.php-fig.org/psr/psr-4/) compatible and can be installed via PHP's dependency manager [Composer](https://getcomposer.org).

```shell
composer require danielburger1337/openid-hash
```

This library requires a 64-bit version of PHP.

---

## **How To Use**

The constructor takes two arguments. The first argument is the [JWA](https://datatracker.ietf.org/doc/html/rfc7518) algorithm the ID Token is signed with. This value can usally be found in the `alg` header parameter of the ID Token.

The second argument is only required when the ID Token is signed with the `EdDSA` algorithm. This argument must then contain the `crv` of the [JWK](https://datatracker.ietf.org/doc/html/rfc7517) that was used to sign the ID Token. This value can usually be found in the `crv` header parameter of the ID Token or in the `jwks_uri` document of the OP.

---

To verify a hash, you can use the `verify*Hash` methods:

```php
verifyAccessTokenHash('access token', 'The "at_hash" claim of the ID Token');
// bool
```

To create a verification hash, you can use the `create*Hash` methods:

```php
createAccessTokenHash('YmJiZTAwYmYtMzgyOC00NzhkLTkyOTItNjJjNDM3MGYzOWIy9sFhvH8K_x8UIHj1osisS57f5DduL');

print $hash; // sB_U72jyb0WgtX8TsVoqJnm6CD295W9gfSDRxkilB3LAL7REi9JYutRW_s1yE4lD8cOfMZf83gi4
```