gyselroth/micro-auth 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gyselroth/micro-auth

最新稳定版本:v1.1.1

Composer 安装命令:

composer require gyselroth/micro-auth

包简介

Authentication implementation including support for LDAP and OpenID-connet

README 文档

README

Build Status Scrutinizer Code Quality Latest Stable Version GitHub release GitHub license

Description

This is a lightweight authentication library. It is adapter based and comes with support for LDAP and OpenID-connect. It can handle multiple adapter of the same or different types. This library contains no storage mechanism. If you wish to store the authentication you need to store the identity object in your sessesion storage.

Requirements

The library is only >= PHP7.1 compatible.

Download

The package is available at packagist: https://packagist.org/packages/gyselroth/micro-auth

To install the package via composer execute:

composer require gyselroth/micro-auth

Documentation

Simple example usage

Create authentication instance and inject an LDAP and OpenID-connect adapter:

use Micro\Auth;

$logger = new \My\Psr\Logger()
$auth = new Auth\Auth(\Psr\Log\LoggerInterface $logger);
$auth->injectAdapter(new Auth\Adapter\Basic\Ldap(new Auth\Ldap([
    'uri' => 'ldap://myldap.local:398',
    'binddn' => 'cn=admin,dc=test,dc=com',
    'bindpw' => '1234',
    'basedn' => 'dc=test,dc=com',
    'tls' => true
]), $logger, [
    'account_filter' => '(&(objectClass=posixAccount)(uid=%s))'
]), 'my_ldap_server');

$auth->injectAdapter(new Auth\Adapter\Oidc([
    'provider_url' => 'https://accounts.google.com',
    'identity_attribute' => 'email'
], $logger), 'google_oidc_server');

if($auth->requireOne()) {
    $identity = $auth->getIdentity();
    printf('Hello %s', $identity->getIdentifier());
} else {
    //Authentication failed
}

Define attribute map

So far so good but usually just authenticate is not enaugh, mostly you like to request user attributes of a given identity. Let us create an attribute map for our ldap server my_ldap_server.

use Micro\Auth;

$auth->injectAdapter(new Auth\Adapter\Basic\Ldap(new Auth\Ldap([
    'uri' => 'ldap://myldap.local:398',
    'binddn' => 'cn=admin,dc=test,dc=com',
    'bindpw' => '1234',
    'basedn' => 'dc=test,dc=com',
    'tls' => true
]), $logger, [
    'account_filter' => '(&(objectClass=posixAccount)(uid=%s))',
    'attribute_map' => [
        'firstname' => [
            'attr' => 'firstname',
            'type' => 'string',
        ],
        'lastname' => [
            'attr' => 'surname',
            'type' => 'string',
        ],
        'mail' => [
            'attr' => 'mail',
            'type' => 'string'
        ]
    ]
]), 'my_ldap_server');

if($auth->requireOne()) {
    $attributes = $auth->getIdentity()->getAttributes();
    var_dump($attributes);
} else {
    //Authentication failed
}

Given that, you can define an attribute map for each authentication adapter and map all attributes to the same attribute names you would like to use.

统计信息

  • 总下载量: 2.72k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固