PHPackages                             safire-ac-za/simplesamlphp-module-sqlattribs - 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. [Database &amp; ORM](/categories/database)
4. /
5. safire-ac-za/simplesamlphp-module-sqlattribs

ActiveSimplesamlphp-module[Database &amp; ORM](/categories/database)

safire-ac-za/simplesamlphp-module-sqlattribs
============================================

SimpleSAMLphp module to provide additional attributes from a SQL database

v2.0.2(7mo ago)14.0k3[1 issues](https://github.com/tenet-ac-za/simplesamlphp-module-sqlattribs/issues)MITPHPPHP ^8.1CI passing

Since Jun 28Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/tenet-ac-za/simplesamlphp-module-sqlattribs)[ Packagist](https://packagist.org/packages/safire-ac-za/simplesamlphp-module-sqlattribs)[ RSS](/packages/safire-ac-za-simplesamlphp-module-sqlattribs/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (9)Dependencies (3)Versions (13)Used By (0)

sqlattribs:AttributeFromSQL
===========================

[](#sqlattribsattributefromsql)

[![Build Status](https://github.com/tenet-ac-za/simplesamlphp-module-sqlattribs/workflows/CI/badge.svg?branch=master)](https://github.com/tenet-ac-za/simplesamlphp-module-sqlattribs/workflows/CI/badge.svg?branch=master)[![Coverage Status](https://camo.githubusercontent.com/fa034427f6b15ec3db63f7375e208efd910a531b0e4fca203c4fd69b37b9af63/68747470733a2f2f636f6465636f762e696f2f67682f74656e65742d61632d7a612f73696d706c6573616d6c7068702d6d6f64756c652d73716c617474726962732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/tenet-ac-za/simplesamlphp-module-sqlattribs)

This SimpleSAMLphp auth proc filter allows you to provides additional attributes from a SQL datastore. It is useful in situations where your primary authsource is a directory (e.g. AD) that you do not have direct control over, and you need to add additional attributes for specific users but cannot add them into the directory/modify the schema.

Installation
------------

[](#installation)

Once you have installed SimpleSAMLphp, installing this module is very simple. Just execute the following command in the root of your SimpleSAMLphp installation:

```
composer.phar require safire-ac-za/simplesamlphp-module-sqlattribs:dev-master

```

where `dev-master` instructs Composer to install the `master` (**development**) branch from the Git repository. See the [releases](https://github.com/tenet-ac-za/simplesamlphp-module-sqlattribs/releases)available if you want to use a stable version of the module.

You then need to create the following table in your SQL database:

```
CREATE TABLE IF NOT EXISTS `AttributeFromSQL` (
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `uid` VARCHAR(100) NOT NULL,
    `sp` VARCHAR(250) DEFAULT '%',
    `attribute` VARCHAR(30) NOT NULL,
    `value` TEXT,
    `expires` DATE DEFAULT '9999-12-31',
     PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
```

Note that if you are upgrading from v1.2 or earlier you need to make the following change to your existing database:

```
ALTER TABLE `AttributeFromSQL` ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id);
ALTER TABLE `AttributeFromSQL` ADD `expires` DATE DEFAULT '9999-12-31';
```

Usage
-----

[](#usage)

This module provides the *sqlattribs:AttributeFromSQL* auth proc filter, which can be used as follows:

```
50 => [
    'class'     => 'sqlattribs:AttributeFromSQL',
    'identifyingAttribute' => 'eduPersonPrincipalName',
    'limit'     => ['eduPersonEntitlement', 'eduPersonAffiliation'],
    'replace'   => false,
    'database'  => [
        'dsn'       => 'mysql:host=localhost;dbname=simplesamlphp',
        'username'  => 'yourDbUsername',
        'password'  => 'yourDbPassword',
        'table'     => 'AttributeFromSQL',
    ],
],
```

Where the parameters are as follows:

- `class` - the name of the class, must be *sqlattribs:AttributeFromSQL*
- `identifyingAttribute` - the attribute to use as the uid/key for database searches, defaults to *eduPersonPrincipalName* if not specified.
- `limit` - an optional array specifying the attribute names we can add. If not specified, all attributes that are found in the database are added. Defaults to allowing all attributes.
- `replace` - behaviour when an existing attribute of the same name is encountered. If `false` (the default) then new values are pushed into an array, creating a multi-valued attribute. If `true`, then existing attributes of the same name are replaced (deleted).
- `ignoreExpiry` - ignore any expiry date (default is to ignore attributes that are beyond the date in the `expires` column).
- `database` - an array containing information about the data store, with the following parameters:

    - `dsn` - the data source name, defaults to *mysql:host=localhost;dbname=simplesamlphp*
    - `username` - the username to connect to the database, defaults to none (blank username)
    - `password` - the password to connect to the database, defaults to none (blank password)
    - `table` - the name of the table/view to search for attributes, defaults to *AttributeFromSQL*
    - `driver_options` - additional driver-specific connection options to pass to the PDO constructor

Adding attributes
-----------------

[](#adding-attributes)

This module provides no interface to add attributes into the database. This can be done manually with SQL similar to the following:

```
INSERT INTO AttributeFromSQL (uid, sp, attribute, value) VALUES ('user@example.org', '%', 'eduPersonEntitlement', 'urn:mace:exampleIdP.org:demoservice:demo-admin');
INSERT INTO AttributeFromSQL (uid, sp, attribute, value) VALUES ('user@example.org', 'https://idp.example.org/idp/shibboleth', 'eduPersonEntitlement', 'urn:mace:grnet.gr:eduroam:admin');
INSERT INTO AttributeFromSQL (uid, sp, attribute, value, expires) VALUES ('user@example.org', '%', 'eduPersonAffiliation', 'faculty', '2020-12-31');
INSERT INTO AttributeFromSQL (uid, attribute, value) VALUES ('user@example.org', 'mail', 'user@example.org');
```

The optional *sp* field (defaults to '%' with the above SQL CREATE) is used to limit which SP sees a particular attribute. The special value `%`is used to indicate all SPs. If you wish to indicate more than one SP but not all, insert multiple lines.

Where multiple attributes of the same name occur, these become a single multi-valued attribute. Thus assuming the user **started with attributes of:

```
$attributes = [
   'eduPersonPrincipalName' => 'user@example.org',
   'eduPersonAffiliation' => ['member'],
   'displayName' => 'Example User',
],
```

The the above SQL table and example auth proc filter would lead to a combined attribute set of:

```
$attributes = [
    'eduPersonPrincipalName' => 'user@example.org',
    'displayName' => 'Example User',
    'eduPersonEntitlement' => [
        'urn:mace:exampleIdP.org:demoservice:demo-admin',
        'urn:mace:grnet.gr:eduroam:admin',
    ],
    'eduPersonAffiliation' => [
        'member',
        'faculty',
    ],
],
```

Note that because the the `limit` parameter, the mail attribute was not added. And because `replace` was false, *eduPersonAffiliation* was merged. It is assumed that this SP has an Entity Id of `https://sp.example.org/shibboleth-sp` - other SPs would not see the SP-specific *eduPersonEntitlement* attribute.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance57

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 88.2% 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.

###  Release Activity

Cadence

Every ~423 days

Recently: every ~598 days

Total

9

Last Release

227d ago

Major Versions

v1.5 → v2.0.02023-03-10

PHP version history (5 changes)v1.4PHP &gt;=5.6

v1.5PHP &gt;=7.4

v2.0.0PHP &gt;=7.4 || ^8.0

v2.0.1PHP ^8.0

v2.0.2PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc6399a58dea776b97dd3ca197ace1c0bc616aab4f442fd7dbdf4e8ef66fcc3f?d=identicon)[ghalse](/maintainers/ghalse)

![](https://www.gravatar.com/avatar/861031e19ef477652b09917f202bd4b909295c31b63c78a8596895fb990bd56d?d=identicon)[tenet-ac-za](/maintainers/tenet-ac-za)

---

Top Contributors

[![ghalse](https://avatars.githubusercontent.com/u/7996633?v=4)](https://github.com/ghalse "ghalse (67 commits)")[![tvdijen](https://avatars.githubusercontent.com/u/841045?v=4)](https://github.com/tvdijen "tvdijen (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![melanger](https://avatars.githubusercontent.com/u/17325174?v=4)](https://github.com/melanger "melanger (2 commits)")[![adigerrens](https://avatars.githubusercontent.com/u/58981829?v=4)](https://github.com/adigerrens "adigerrens (1 commits)")

---

Tags

saml2simplesamlphpsimplesamlphp-installationsimplesamlphp-modulesqlsqlpdosimplesamlphpsqlattribs

### Embed Badge

![Health badge](/badges/safire-ac-za-simplesamlphp-module-sqlattribs/health.svg)

```
[![Health](https://phpackages.com/badges/safire-ac-za-simplesamlphp-module-sqlattribs/health.svg)](https://phpackages.com/packages/safire-ac-za-simplesamlphp-module-sqlattribs)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[paragonie/easydb

Easy-to-use database abstraction

744273.4k23](/packages/paragonie-easydb)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86946.7k](/packages/ezsql-ezsql)

PHPackages © 2026

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