Edgard преди 6 години
родител
ревизия
c4af8cbb5e
променени са 11 файла, в които са добавени 1653 реда и са изтрити 1 реда
  1. 20 0
      .editorconfig
  2. 2 0
      .gitignore
  3. 0 1
      README.md
  4. 15 0
      composer.json
  5. 735 0
      composer.lock
  6. 116 0
      front/callback.php
  7. 15 0
      front/provider.form.php
  8. 17 0
      front/provider.php
  9. 107 0
      hook.php
  10. 566 0
      inc/provider.class.php
  11. 60 0
      setup.php

+ 20 - 0
.editorconfig

@@ -0,0 +1,20 @@
+# EditorConfig helps developers define and maintain consistent
+# coding styles between different editors and IDEs
+# editorconfig.org
+
+root = true
+
+[*]
+
+# Change these settings to your own preference
+indent_style = space
+indent_size = 3
+
+# We recommend you to keep these unchanged
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+/nbproject
+/vendor

+ 0 - 1
README.md

@@ -1 +0,0 @@
-# glpi-singlesignon

+ 15 - 0
composer.json

@@ -0,0 +1,15 @@
+{
+    "require": {
+        "league/oauth2-client": "^2.2",
+        "league/oauth2-facebook": "^2.0",
+        "league/oauth2-github": "^2.0",
+        "league/oauth2-google": "^2.0",
+        "league/oauth2-instagram": "^2.0",
+        "league/oauth2-linkedin": "^2.0"
+    },
+    "config": {
+        "platform": {
+            "php": "5.6"
+        }
+    }
+}

+ 735 - 0
composer.lock

@@ -0,0 +1,735 @@
+{
+    "_readme": [
+        "This file locks the dependencies of your project to a known state",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+        "This file is @generated automatically"
+    ],
+    "content-hash": "b586139b80f70524bf5995e6e42dd7c4",
+    "packages": [
+        {
+            "name": "eloquent/phony",
+            "version": "0.14.6",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/eloquent/phony.git",
+                "reference": "1ef22360a48abc2d8d9ede2db67112240cddac06"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/eloquent/phony/zipball/1ef22360a48abc2d8d9ede2db67112240cddac06",
+                "reference": "1ef22360a48abc2d8d9ede2db67112240cddac06",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.3"
+            },
+            "require-dev": {
+                "athletic/athletic": "^0.1",
+                "counterpart/counterpart": "^1",
+                "danielstjules/pho": "^1",
+                "errors/exceptions": "dev-master",
+                "ext-pdo": "*",
+                "friendsofphp/php-cs-fixer": "1.11.4",
+                "hamcrest/hamcrest-php": "^2",
+                "icecave/isolator": "^3",
+                "icecave/semver": "^3",
+                "mockery/mockery": "^0.9",
+                "peridot-php/leo": "^1",
+                "peridot-php/peridot": "^1",
+                "phake/phake": "^2",
+                "phpdocumentor/reflection-docblock": "^2",
+                "phpspec/prophecy": "^1",
+                "phpunit/php-code-coverage": "^2",
+                "phpunit/phpunit": "^4",
+                "simpletest/simpletest": "^1"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Eloquent\\Phony\\": "src"
+                },
+                "files": [
+                    "src/functions.php",
+                    "src/Pho/functions.php",
+                    "src/Phpunit/functions.php",
+                    "src/Simpletest/functions.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Erin Millard",
+                    "email": "ezzatron@gmail.com",
+                    "homepage": "http://ezzatron.com/"
+                }
+            ],
+            "description": "Mocks, stubs, and spies for PHP.",
+            "homepage": "https://github.com/eloquent/phony",
+            "keywords": [
+                "Double",
+                "Dummy",
+                "fake",
+                "mock",
+                "mocking",
+                "spy",
+                "stub",
+                "stubbing",
+                "test"
+            ],
+            "time": "2017-01-03T03:48:40+00:00"
+        },
+        {
+            "name": "guzzlehttp/guzzle",
+            "version": "6.2.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/guzzle/guzzle.git",
+                "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
+                "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
+                "shasum": ""
+            },
+            "require": {
+                "guzzlehttp/promises": "^1.0",
+                "guzzlehttp/psr7": "^1.3.1",
+                "php": ">=5.5"
+            },
+            "require-dev": {
+                "ext-curl": "*",
+                "phpunit/phpunit": "^4.0",
+                "psr/log": "^1.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "6.2-dev"
+                }
+            },
+            "autoload": {
+                "files": [
+                    "src/functions_include.php"
+                ],
+                "psr-4": {
+                    "GuzzleHttp\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Michael Dowling",
+                    "email": "mtdowling@gmail.com",
+                    "homepage": "https://github.com/mtdowling"
+                }
+            ],
+            "description": "Guzzle is a PHP HTTP client library",
+            "homepage": "http://guzzlephp.org/",
+            "keywords": [
+                "client",
+                "curl",
+                "framework",
+                "http",
+                "http client",
+                "rest",
+                "web service"
+            ],
+            "time": "2016-10-08T15:01:37+00:00"
+        },
+        {
+            "name": "guzzlehttp/promises",
+            "version": "v1.3.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/guzzle/promises.git",
+                "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
+                "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.5.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.4-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "GuzzleHttp\\Promise\\": "src/"
+                },
+                "files": [
+                    "src/functions_include.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Michael Dowling",
+                    "email": "mtdowling@gmail.com",
+                    "homepage": "https://github.com/mtdowling"
+                }
+            ],
+            "description": "Guzzle promises library",
+            "keywords": [
+                "promise"
+            ],
+            "time": "2016-12-20T10:07:11+00:00"
+        },
+        {
+            "name": "guzzlehttp/psr7",
+            "version": "1.3.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/guzzle/psr7.git",
+                "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b",
+                "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.4.0",
+                "psr/http-message": "~1.0"
+            },
+            "provide": {
+                "psr/http-message-implementation": "1.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.4-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "GuzzleHttp\\Psr7\\": "src/"
+                },
+                "files": [
+                    "src/functions_include.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Michael Dowling",
+                    "email": "mtdowling@gmail.com",
+                    "homepage": "https://github.com/mtdowling"
+                }
+            ],
+            "description": "PSR-7 message implementation",
+            "keywords": [
+                "http",
+                "message",
+                "stream",
+                "uri"
+            ],
+            "time": "2016-06-24T23:00:38+00:00"
+        },
+        {
+            "name": "jakeasmith/http_build_url",
+            "version": "1.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/jakeasmith/http_build_url.git",
+                "reference": "15bdd686e5178ddfa3e88de60fa585adffb292bb"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/jakeasmith/http_build_url/zipball/15bdd686e5178ddfa3e88de60fa585adffb292bb",
+                "reference": "15bdd686e5178ddfa3e88de60fa585adffb292bb",
+                "shasum": ""
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~3.7"
+            },
+            "type": "library",
+            "autoload": {
+                "files": [
+                    "src/http_build_url.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Jake A. Smith",
+                    "email": "theman@jakeasmith.com"
+                }
+            ],
+            "description": "Provides functionality for http_build_url() to environments without pecl_http.",
+            "time": "2015-05-06T12:27:20+00:00"
+        },
+        {
+            "name": "league/oauth2-client",
+            "version": "2.2.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/thephpleague/oauth2-client.git",
+                "reference": "5f57366c99ac013ee9d78670c1fc0b9ca7871d95"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/5f57366c99ac013ee9d78670c1fc0b9ca7871d95",
+                "reference": "5f57366c99ac013ee9d78670c1fc0b9ca7871d95",
+                "shasum": ""
+            },
+            "require": {
+                "guzzlehttp/guzzle": "^6.0",
+                "paragonie/random_compat": "^2.0",
+                "php": ">=5.6.0"
+            },
+            "require-dev": {
+                "eloquent/liberator": "^2.0",
+                "eloquent/phony": "^0.14.1",
+                "jakub-onderka/php-parallel-lint": "~0.9",
+                "phpunit/phpunit": "^5.0",
+                "squizlabs/php_codesniffer": "^2.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-2.x": "2.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "League\\OAuth2\\Client\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Alex Bilbie",
+                    "email": "hello@alexbilbie.com",
+                    "homepage": "http://www.alexbilbie.com",
+                    "role": "Developer"
+                },
+                {
+                    "name": "Woody Gilk",
+                    "homepage": "https://github.com/shadowhand",
+                    "role": "Contributor"
+                }
+            ],
+            "description": "OAuth 2.0 Client Library",
+            "keywords": [
+                "Authentication",
+                "SSO",
+                "authorization",
+                "identity",
+                "idp",
+                "oauth",
+                "oauth2",
+                "single sign on"
+            ],
+            "time": "2017-02-02T04:08:45+00:00"
+        },
+        {
+            "name": "league/oauth2-facebook",
+            "version": "2.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/thephpleague/oauth2-facebook.git",
+                "reference": "3843204ccd856eed7d726afc2ef5afa12122d572"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/thephpleague/oauth2-facebook/zipball/3843204ccd856eed7d726afc2ef5afa12122d572",
+                "reference": "3843204ccd856eed7d726afc2ef5afa12122d572",
+                "shasum": ""
+            },
+            "require": {
+                "league/oauth2-client": "^2.0",
+                "php": "^5.6 || ^7.0"
+            },
+            "require-dev": {
+                "mockery/mockery": "~0.9",
+                "phpunit/phpunit": "~4.0",
+                "squizlabs/php_codesniffer": "~2.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "League\\OAuth2\\Client\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Sammy Kaye Powers",
+                    "email": "me@sammyk.me",
+                    "homepage": "http://www.sammyk.me"
+                }
+            ],
+            "description": "Facebook OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
+            "keywords": [
+                "Authentication",
+                "authorization",
+                "client",
+                "facebook",
+                "oauth",
+                "oauth2"
+            ],
+            "time": "2017-01-25T14:36:10+00:00"
+        },
+        {
+            "name": "league/oauth2-github",
+            "version": "2.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/thephpleague/oauth2-github.git",
+                "reference": "e63d64f3ec167c09232d189c6b0c397458a99357"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/thephpleague/oauth2-github/zipball/e63d64f3ec167c09232d189c6b0c397458a99357",
+                "reference": "e63d64f3ec167c09232d189c6b0c397458a99357",
+                "shasum": ""
+            },
+            "require": {
+                "league/oauth2-client": "^2.0"
+            },
+            "require-dev": {
+                "mockery/mockery": "~0.9",
+                "phpunit/phpunit": "~4.0",
+                "squizlabs/php_codesniffer": "~2.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "League\\OAuth2\\Client\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Steven Maguire",
+                    "email": "stevenmaguire@gmail.com",
+                    "homepage": "https://github.com/stevenmaguire"
+                }
+            ],
+            "description": "Github OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
+            "keywords": [
+                "authorisation",
+                "authorization",
+                "client",
+                "github",
+                "oauth",
+                "oauth2"
+            ],
+            "time": "2017-01-26T01:14:51+00:00"
+        },
+        {
+            "name": "league/oauth2-google",
+            "version": "2.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/thephpleague/oauth2-google.git",
+                "reference": "365ceed2d068fa4c0bde41afb0acc6c2976f0c22"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/thephpleague/oauth2-google/zipball/365ceed2d068fa4c0bde41afb0acc6c2976f0c22",
+                "reference": "365ceed2d068fa4c0bde41afb0acc6c2976f0c22",
+                "shasum": ""
+            },
+            "require": {
+                "eloquent/phony": "^0.14.6",
+                "league/oauth2-client": "^2.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^5.0",
+                "squizlabs/php_codesniffer": "^2.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "League\\OAuth2\\Client\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Woody Gilk",
+                    "email": "woody.gilk@gmail.com",
+                    "homepage": "http://shadowhand.me"
+                }
+            ],
+            "description": "Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
+            "keywords": [
+                "Authentication",
+                "authorization",
+                "client",
+                "google",
+                "oauth",
+                "oauth2"
+            ],
+            "time": "2017-01-24T15:15:42+00:00"
+        },
+        {
+            "name": "league/oauth2-instagram",
+            "version": "2.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/thephpleague/oauth2-instagram.git",
+                "reference": "abf6466ebd2c2a73e920b0ce834e2bf50d1abdcc"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/thephpleague/oauth2-instagram/zipball/abf6466ebd2c2a73e920b0ce834e2bf50d1abdcc",
+                "reference": "abf6466ebd2c2a73e920b0ce834e2bf50d1abdcc",
+                "shasum": ""
+            },
+            "require": {
+                "jakeasmith/http_build_url": "^1.0",
+                "league/oauth2-client": "^2.0"
+            },
+            "require-dev": {
+                "mockery/mockery": "~0.9",
+                "phpunit/phpunit": "~4.0",
+                "squizlabs/php_codesniffer": "~2.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "League\\OAuth2\\Client\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Steven Maguire",
+                    "email": "stevenmaguire@gmail.com",
+                    "homepage": "https://github.com/stevenmaguire"
+                }
+            ],
+            "description": "Instagram OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
+            "keywords": [
+                "authorisation",
+                "authorization",
+                "client",
+                "instagram",
+                "oauth",
+                "oauth2"
+            ],
+            "time": "2017-01-26T01:21:29+00:00"
+        },
+        {
+            "name": "league/oauth2-linkedin",
+            "version": "2.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/thephpleague/oauth2-linkedin.git",
+                "reference": "d7642ae8a44f19af75cc8af01b8f6de206d293e1"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/thephpleague/oauth2-linkedin/zipball/d7642ae8a44f19af75cc8af01b8f6de206d293e1",
+                "reference": "d7642ae8a44f19af75cc8af01b8f6de206d293e1",
+                "shasum": ""
+            },
+            "require": {
+                "league/oauth2-client": "^2.0"
+            },
+            "require-dev": {
+                "mockery/mockery": "~0.9",
+                "phpunit/phpunit": "~4.0",
+                "squizlabs/php_codesniffer": "~2.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "League\\OAuth2\\Client\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Steven Maguire",
+                    "email": "stevenmaguire@gmail.com",
+                    "homepage": "https://github.com/stevenmaguire"
+                }
+            ],
+            "description": "LinkedIn OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
+            "keywords": [
+                "authorisation",
+                "authorization",
+                "client",
+                "linkedin",
+                "oauth",
+                "oauth2"
+            ],
+            "time": "2017-01-26T01:30:16+00:00"
+        },
+        {
+            "name": "paragonie/random_compat",
+            "version": "v2.0.4",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/paragonie/random_compat.git",
+                "reference": "a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/paragonie/random_compat/zipball/a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e",
+                "reference": "a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.2.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "4.*|5.*"
+            },
+            "suggest": {
+                "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
+            },
+            "type": "library",
+            "autoload": {
+                "files": [
+                    "lib/random.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Paragon Initiative Enterprises",
+                    "email": "security@paragonie.com",
+                    "homepage": "https://paragonie.com"
+                }
+            ],
+            "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
+            "keywords": [
+                "csprng",
+                "pseudorandom",
+                "random"
+            ],
+            "time": "2016-11-07T23:38:38+00:00"
+        },
+        {
+            "name": "psr/http-message",
+            "version": "1.0.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/php-fig/http-message.git",
+                "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
+                "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.3.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Psr\\Http\\Message\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "PHP-FIG",
+                    "homepage": "http://www.php-fig.org/"
+                }
+            ],
+            "description": "Common interface for HTTP messages",
+            "homepage": "https://github.com/php-fig/http-message",
+            "keywords": [
+                "http",
+                "http-message",
+                "psr",
+                "psr-7",
+                "request",
+                "response"
+            ],
+            "time": "2016-08-06T14:39:51+00:00"
+        }
+    ],
+    "packages-dev": [],
+    "aliases": [],
+    "minimum-stability": "stable",
+    "stability-flags": [],
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": [],
+    "platform-dev": [],
+    "platform-overrides": {
+        "php": "5.6"
+    }
+}

+ 116 - 0
front/callback.php

@@ -0,0 +1,116 @@
+<?php
+
+//Disable CSRF token
+//define('GLPI_USE_CSRF_CHECK', 0);
+
+include ('../../../inc/includes.php');
+
+$params = [];
+
+if (isset($_SERVER['PATH_INFO'])) {
+   $path_info = trim($_SERVER['PATH_INFO'], '/');
+
+   $parts = explode('/', $path_info);
+
+   $key = null;
+
+   foreach ($parts as $part) {
+      $part = str_replace('~', '/', $part);
+      if ($key === null) {
+         $key = $part;
+      } else {
+         $params[$key] = $part;
+         $key = null;
+      }
+   }
+}
+
+if (!isset($params['provider'])) {
+   Html::displayErrorAndDie(__sso("Provider not defined."), false);
+}
+
+$provider_id = (int) $params['provider'];
+
+
+$signon_provider = new PluginSinglesignonProvider();
+
+if (!$signon_provider->getFromDB($provider_id)) {
+   Html::displayErrorAndDie(__sso("Provider not found."), true);
+}
+
+if (!$signon_provider->fields['is_active']) {
+   Html::displayErrorAndDie(__sso("Provider not active."), true);
+}
+
+$httpClient = new GuzzleHttp\Client([
+   'verify' => false,
+      ]);
+
+$collaborators = [
+   'httpClient' => $httpClient,
+];
+
+$provider = $signon_provider->prepareProviderInstance([], $collaborators);
+
+$signon_provider->checkAuthorization();
+
+if ($signon_provider->login()) {
+   $url_redirect = '';
+
+   $REDIRECT = "";
+
+   if (isset($params['redirect'])) {
+      $REDIRECT = '?redirect=' . $params['redirect'];
+   }
+
+   if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
+      if ($_SESSION['glpiactiveprofile']['create_ticket_on_login'] && empty($REDIRECT)) {
+         $url_redirect = $CFG_GLPI['root_doc'] . "/front/helpdesk.public.php?create_ticket=1";
+      } else {
+         $url_redirect = $CFG_GLPI['root_doc'] . "/front/helpdesk.public.php$REDIRECT";
+      }
+   } else {
+      if ($_SESSION['glpiactiveprofile']['create_ticket_on_login'] && empty($REDIRECT)) {
+         $url_redirect = $CFG_GLPI['root_doc'] . "/front/ticket.form.php";
+      } else {
+         $url_redirect = $CFG_GLPI['root_doc'] . "/front/central.php$REDIRECT";
+      }
+   }
+
+   echo "<script type=\"text/javascript\">
+           if (window.opener) {
+              window.opener.location='" . $url_redirect . "';
+              window.close();
+           } else {
+              window.location='" . $url_redirect . "';
+           }
+         </script>";
+   exit();
+}
+
+
+try {
+// Try to get an access token (using the authorization code grant)
+   $token = $provider->getAccessToken('authorization_code', [
+      'code' => $_GET['code']
+   ]);
+
+   var_dump($token);
+
+// Optional: Now you have a token you can look up a users profile data
+   // We got an access token, let's now get the user's details
+   $user = $provider->getResourceOwner($token);
+
+   // Use these details to create a new profile
+   printf('Hello %s!', $user->getNickname());
+
+   var_dump($user->toArray());
+} catch (Exception $e) {
+   var_dump($e);
+
+   // Failed to get user details
+   exit('Oh dear...' . $e->getMessage());
+}
+
+// Use this to interact with an API on the users behalf
+echo $token->getToken();

+ 15 - 0
front/provider.form.php

@@ -0,0 +1,15 @@
+<?php
+
+include ('../../../inc/includes.php');
+
+if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
+   Html::header("TITRE", $_SERVER['PHP_SELF'],"plugins","pluginexampleexample","");
+} else {
+   Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
+}
+
+$example = new PluginSinglesignonProvider();
+$example->display($_GET);
+
+Html::footer();
+?>

+ 17 - 0
front/provider.php

@@ -0,0 +1,17 @@
+<?php
+
+include ('../../../inc/includes.php');
+
+if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
+   Html::header("TITRE", $_SERVER['PHP_SELF'], "config", "pluginsinglesignonprovider", "");
+} else {
+   Html::helpHeader("TITRE", $_SERVER['PHP_SELF']);
+}
+
+
+//checkTypeRight('PluginExampleExample',"r");
+
+Search::show('PluginSinglesignonProvider');
+
+Html::footer();
+?>

+ 107 - 0
hook.php

@@ -0,0 +1,107 @@
+<?php
+
+function plugin_singlesignon_display_login() {
+   global $CFG_GLPI;
+
+   $url_prefix = $CFG_GLPI['root_doc'] . '/plugins/singlesignon/front/callback.php';
+   $url_sufix = '';
+
+   if (isset($_POST['redirect']) && (strlen($_POST['redirect']) > 0)) {
+      $url_sufix = "/redirect/" . str_replace('/', '~', $_POST['redirect']);
+   } else if (isset($_GET['redirect']) && strlen($_GET['redirect']) > 0) {
+      $url_sufix = "/redirect/" . str_replace('/', '~', $_GET['redirect']);
+   }
+
+
+   $signon_provider = new PluginSinglesignonProvider();
+
+   $rows = $signon_provider->find('`is_active` = 1');
+
+   $html = [];
+
+   foreach ($rows as $row) {
+      $html[] = '<a href="' . $url_prefix . '/provider/' . $row['id'] . $url_sufix . '" style="color: #CFCFCF">[ Login with ' . $row['name'] . ' ]</a>';
+   }
+
+   echo implode("<br />\n", $html);
+}
+
+function plugin_singlesignon_install() {
+   /* @var $DB DB */
+   global $DB;
+
+   $currentVersion = '0.0.0';
+
+   $default = [
+   ];
+
+   $current = Config::getConfigurationValues('singlesignon');
+
+   if (isset($current['version'])) {
+      $currentVersion = $current['version'];
+   }
+
+   foreach ($default as $key => $value) {
+      if (!isset($current[$key])) {
+         $current[$key] = $value;
+      }
+   }
+
+   Config::setConfigurationValues('singlesignon', $current);
+
+   if (!TableExists("glpi_plugin_singlesignon_providers")) {
+      $query = "CREATE TABLE `glpi_plugin_singlesignon_providers` (
+                  `id`                         int(11) NOT NULL auto_increment,
+                  `type`                       varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+                  `name`                       varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+                  `client_id`                  varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+                  `client_secret`              varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+                  `scope`                      varchar(255) COLLATE utf8_unicode_ci NULL,
+                  `extra_options`              varchar(255) COLLATE utf8_unicode_ci NULL,
+                  `url_authorize`              varchar(255) COLLATE utf8_unicode_ci NULL,
+                  `url_access_token`           varchar(255) COLLATE utf8_unicode_ci NULL,
+                  `url_resource_owner_details` varchar(255) COLLATE utf8_unicode_ci NULL,
+                  `is_active`                  tinyint(1) NOT NULL DEFAULT '0',
+                  `is_deleted`                 tinyint(1) NOT NULL default '0',
+                  `comment`                    text COLLATE utf8_unicode_ci,
+                  `date_mod`                   datetime DEFAULT NULL,
+                  `date_creation`              datetime DEFAULT NULL,
+                  PRIMARY KEY (`id`),
+                  KEY `date_mod` (`date_mod`),
+                  KEY `date_creation` (`date_creation`)
+               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
+
+      $DB->query($query) or die("error creating glpi_plugin_singlesignon_providers " . $DB->error());
+
+//      $query = "INSERT INTO `glpi_plugin_singlesignon_providers`
+//                       (`id`, `name`, `serial`, `is_deleted`)
+//                VALUES (1, 'example 1', 'serial 1', 0),
+//                       (2, 'example 2', 'serial 2', 0),
+//                       (3, 'example 3', 'serial 3', 0)";
+//      $DB->query($query) or die("error populate glpi_plugin_example " . $DB->error());
+   }
+
+   Config::setConfigurationValues('singlesignon', [
+      'version' => PLUGIN_SINGLESIGNON_VERSION,
+   ]);
+   return true;
+}
+
+function plugin_singlesignon_uninstall() {
+   global $DB;
+
+   $config = new Config();
+   $rows = $config->find("`context` LIKE 'singlesignon%'");
+
+   foreach ($rows as $id => $row) {
+      $config->delete(['id' => $id]);
+   }
+
+   // Old version tables
+   if (TableExists("glpi_plugin_singlesignon_providers")) {
+      $query = "DROP TABLE `glpi_plugin_singlesignon_providers`";
+      $DB->query($query) or die("error deleting glpi_plugin_singlesignon_providers");
+   }
+
+   return true;
+}

+ 566 - 0
inc/provider.class.php

@@ -0,0 +1,566 @@
+<?php
+
+class PluginSinglesignonProvider extends CommonDBTM {
+
+   static $rightname = 'config';
+
+   /**
+    * Provider instance
+    * @var null|\League\OAuth2\Client\Provider\GenericProvider
+    */
+   protected $_provider = null;
+   protected $_code = null;
+
+   /**
+    *
+    * @var null|\League\OAuth2\Client\Token\AccessToken
+    */
+   protected $_token = null;
+
+   /**
+    *
+    * @var null|\League\OAuth2\Client\Provider\ResourceOwnerInterface
+    */
+   protected $_resource_owner = null;
+
+   public static function canCreate() {
+      if (static::$rightname) {
+         return Session::haveRight(static::$rightname, UPDATE);
+      }
+      return false;
+   }
+
+   // Should return the localized name of the type
+   static function getTypeName($nb = 0) {
+      return __sso('Single Sign-on Provider');
+   }
+
+   /**
+    * @see CommonGLPI::getMenuName()
+    * */
+   static function getMenuName() {
+      return __sso('Single Sign-on');
+   }
+
+   /**
+    * @see CommonGLPI::getAdditionalMenuLinks()
+    * */
+   static function getAdditionalMenuLinks() {
+      global $CFG_GLPI;
+      $links = array();
+
+//      $links['add'] = '/plugins/singlesignon/front/provider.form.php';
+//      $links['config'] = '/plugins/singlesignon/index.php';
+      $links["<img  src='" . $CFG_GLPI["root_doc"] . "/pics/menu_showall.png' title='" . __s('Show all') . "' alt='" . __s('Show all') . "'>"] = '/plugins/singlesignon/index.php';
+      $links[__s('Test link', 'singlesignon')] = '/plugins/singlesignon/index.php';
+
+      return $links;
+   }
+
+//   public function maybeTemplate() {
+//      parent::maybeTemplate();
+//   }
+
+   function defineTabs($options = array()) {
+
+      $ong = array();
+      $this->addDefaultFormTab($ong);
+      $this->addStandardTab('Link', $ong, $options);
+
+      return $ong;
+   }
+
+   function showForm($ID, $options = array()) {
+      global $CFG_GLPI;
+
+      $this->initForm($ID, $options);
+      $this->showFormHeader($options);
+
+      echo "<tr class='tab_bg_1'>";
+
+      echo "<td>" . __('ID') . "</td>";
+      echo "<td>";
+      echo $ID;
+      echo "</td>";
+
+      $this->showFormButtons($options);
+
+      return true;
+   }
+
+   function getSearchOptions() {
+
+      $tab = array();
+      $tab['common'] = __('Characteristics');
+
+      $tab[1]['table'] = $this->getTable();
+      $tab[1]['field'] = 'type';
+      $tab[1]['name'] = __('Type');
+      $tab[1]['searchtype'] = 'equals';
+      $tab[1]['datatype'] = 'specific';
+
+      $tab[2]['table'] = $this->getTable();
+      $tab[2]['field'] = 'name';
+      $tab[2]['name'] = __('Name');
+      $tab[2]['datatype'] = 'text';
+
+      $tab[3]['table'] = $this->getTable();
+      $tab[3]['field'] = 'client_id';
+      $tab[3]['name'] = __sso('Client ID');
+      $tab[3]['datatype'] = 'text';
+
+      $tab[4]['table'] = $this->getTable();
+      $tab[4]['field'] = 'client_secret';
+      $tab[4]['name'] = __sso('Client Secret');
+      $tab[4]['datatype'] = 'text';
+
+      $tab[5]['table'] = $this->getTable();
+      $tab[5]['field'] = 'scope';
+      $tab[5]['name'] = __sso('Client Secret');
+      $tab[5]['datatype'] = 'text';
+
+      $tab[6]['table'] = $this->getTable();
+      $tab[6]['field'] = 'extra_options';
+      $tab[6]['name'] = __sso('Extra Options');
+      $tab[6]['datatype'] = 'text';
+
+      $tab[7]['table'] = $this->getTable();
+      $tab[7]['field'] = 'url_authorize';
+      $tab[7]['name'] = __sso('URL Authorize');
+      $tab[7]['datatype'] = 'weblink';
+
+      $tab[8]['table'] = $this->getTable();
+      $tab[8]['field'] = 'url_access_token';
+      $tab[8]['name'] = __sso('URL Access Token');
+      $tab[8]['datatype'] = 'weblink';
+
+      $tab[9]['table'] = $this->getTable();
+      $tab[9]['field'] = 'url_resource_owner_details';
+      $tab[9]['name'] = __sso('URL Resource Owner Details');
+      $tab[9]['datatype'] = 'weblink';
+
+      $tab[10]['table'] = $this->getTable();
+      $tab[10]['field'] = 'is_active';
+      $tab[10]['name'] = __('Active');
+      $tab[10]['searchtype'] = 'equals';
+      $tab[10]['datatype'] = 'bool';
+
+      $tab[30]['table'] = $this->getTable();
+      $tab[30]['field'] = 'id';
+      $tab[30]['name'] = __('ID');
+
+      return $tab;
+   }
+
+   static function getSpecificValueToDisplay($field, $values, array $options = array()) {
+
+      if (!is_array($values)) {
+         $values = array($field => $values);
+      }
+      switch ($field) {
+         case 'type':
+            return self::getTicketTypeName($values[$field]);
+         case 'extra_options':
+            return '<pre>' . $values[$field] . '</pre>';
+      }
+      return '';
+   }
+
+   static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = array()) {
+
+      if (!is_array($values)) {
+         $values = array($field => $values);
+      }
+      $options['display'] = false;
+      switch ($field) {
+         case 'type':
+            $options['value'] = $values[$field];
+            return self::dropdownType($name, $options);
+      }
+      return parent::getSpecificValueToSelect($field, $name, $values, $options);
+   }
+
+   /**
+    * Get ticket types
+    *
+    * @return array of types
+    * */
+   static function getTypes() {
+
+      $options['generic'] = __sso('Generic');
+      $options['facebook'] = __sso('Facebook');
+      $options['github'] = __sso('GitHub');
+      $options['google'] = __sso('Google');
+      $options['instagram'] = __sso('Instagram');
+      $options['linkedin'] = __sso('LinkdeIn');
+
+      return $options;
+   }
+
+   /**
+    * Get ticket type Name
+    *
+    * @param $value type ID
+    * */
+   static function getTicketTypeName($value) {
+      $tab = static::getTypes();
+      // Return $value if not defined
+      return (isset($tab[$value]) ? $tab[$value] : $value);
+   }
+
+   /**
+    * Dropdown of ticket type
+    *
+    * @param $name            select name
+    * @param $options   array of options:
+    *    - value     : integer / preselected value (default 0)
+    *    - toadd     : array / array of specific values to add at the begining
+    *    - on_change : string / value to transmit to "onChange"
+    *    - display   : boolean / display or get string (default true)
+    *
+    * @return string id of the select
+    * */
+   static function dropdownType($name, $options = array()) {
+
+      $params['value'] = 0;
+      $params['toadd'] = array();
+      $params['on_change'] = '';
+      $params['display'] = true;
+
+      if (is_array($options) && count($options)) {
+         foreach ($options as $key => $val) {
+            $params[$key] = $val;
+         }
+      }
+
+      $items = array();
+      if (count($params['toadd']) > 0) {
+         $items = $params['toadd'];
+      }
+
+      $items += self::getTypes();
+
+      return Dropdown::showFromArray($name, $items, $params);
+   }
+
+   /**
+    * Get an history entry message
+    *
+    * @param $data Array from glpi_logs table
+    *
+    * @since GLPI version 0.84
+    *
+    * @return string
+    * */
+   static function getHistoryEntry($data) {
+
+      switch ($data['linked_action'] - Log::HISTORY_PLUGIN) {
+         case 0:
+            return __('History from plugin example', 'example');
+      }
+
+      return '';
+   }
+
+//////////////////////////////
+////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////
+   /**
+    * @since version 0.85
+    *
+    * @see CommonDBTM::getSpecificMassiveActions()
+    * */
+   function getSpecificMassiveActions($checkitem = NULL) {
+
+      $actions = parent::getSpecificMassiveActions($checkitem);
+
+      $actions['Document_Item' . MassiveAction::CLASS_ACTION_SEPARATOR . 'add'] = _x('button', 'Add a document');         // GLPI core one
+      $actions[__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'do_nothing'] = __('Do Nothing - just for fun', 'example');  // Specific one
+
+      return $actions;
+   }
+
+   /**
+    * @since version 0.85
+    *
+    * @see CommonDBTM::showMassiveActionsSubForm()
+    * */
+   static function showMassiveActionsSubForm(MassiveAction $ma) {
+
+      switch ($ma->getAction()) {
+         case 'DoIt':
+            echo "&nbsp;<input type='hidden' name='toto' value='1'>" .
+            Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')) .
+            " " . __('Write in item history', 'example');
+            return true;
+         case 'do_nothing' :
+            echo "&nbsp;" . Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')) .
+            " " . __('but do nothing :)', 'example');
+            return true;
+      }
+      return parent::showMassiveActionsSubForm($ma);
+   }
+
+   /**
+    * @since version 0.85
+    *
+    * @see CommonDBTM::processMassiveActionsForOneItemtype()
+    * */
+   static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) {
+      global $DB;
+
+      switch ($ma->getAction()) {
+         case 'DoIt' :
+            if ($item->getType() == 'Computer') {
+               Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
+               Session::addMessageAfterRedirect(__('Write in item history', 'example'));
+               $changes = array(0, 'old value', 'new value');
+               foreach ($ids as $id) {
+                  if ($item->getFromDB($id)) {
+                     Session::addMessageAfterRedirect("- " . $item->getField("name"));
+                     Log::history($id, 'Computer', $changes, 'PluginExampleExample', Log::HISTORY_PLUGIN);
+                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
+                  } else {
+                     // Example of ko count
+                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
+                  }
+               }
+            } else {
+               // When nothing is possible ...
+               $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
+            }
+            return;
+
+         case 'do_nothing' :
+            If ($item->getType() == 'PluginExampleExample') {
+               Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
+               Session::addMessageAfterRedirect(__("But... I say I will do nothing for:", 'example'));
+               foreach ($ids as $id) {
+                  if ($item->getFromDB($id)) {
+                     Session::addMessageAfterRedirect("- " . $item->getField("name"));
+                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
+                  } else {
+                     // Example for noright / Maybe do it with can function is better
+                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
+                  }
+               }
+            } else {
+               $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
+            }
+            Return;
+      }
+      parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
+   }
+
+   /**
+    * 
+    * @param string $type
+    * @param array $options
+    * @param array $collaborators
+    * @return \League\OAuth2\Client\Provider\AbstractProvider
+    */
+   public static function createInstance($type = 'generic', array $options = [], array $collaborators = []) {
+      switch ($type) {
+         case 'facebook':
+            if (!isset($options['graphApiVersion'])) {
+               $options['graphApiVersion'] = 'v2.8';
+            }
+            return new League\OAuth2\Client\Provider\Facebook($options, $collaborators);
+         case 'github':
+            return new League\OAuth2\Client\Provider\Github($options, $collaborators);
+         case 'google':
+            return new League\OAuth2\Client\Provider\Google($options, $collaborators);
+         case 'instagram':
+            return new League\OAuth2\Client\Provider\Instagram($options, $collaborators);
+         case 'linkedin':
+            return new League\OAuth2\Client\Provider\LinkedIn($options, $collaborators);
+         case 'generic':
+         default:
+            return new League\OAuth2\Client\Provider\GenericProvider($options, $collaborators);
+      }
+   }
+
+   private function getCurrentURL() {
+      $currentURL = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https://" : "http://";
+      $currentURL .= $_SERVER["SERVER_NAME"];
+
+      if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
+         $currentURL .= ":" . $_SERVER["SERVER_PORT"];
+      }
+
+      $currentURL .= $_SERVER["REQUEST_URI"];
+      return $currentURL;
+   }
+
+   public function prepareProviderInstance(array $options = [], array $collaborators = []) {
+      global $CFG_GLPI;
+
+      if ($this->_provider === null) {
+
+         $redirect_uri = $this->getCurrentURL();
+
+         $type = $this->fields['type'];
+         $default = [
+            'clientId'     => $this->fields['client_id'],
+            'clientSecret' => $this->fields['client_secret'],
+            'redirectUri'  => $redirect_uri,
+         ];
+
+         if ($type === 'generic') {
+            $default['urlAuthorize'] = $this->fields['url_authorize'];
+            $default['urlAccessToken'] = $this->fields['url_accessToken'];
+            $default['urlResourceOwnerDetails'] = $this->fields['url_resource_owner_details'];
+         }
+
+         if (!empty($this->fields['extra_options'])) {
+            try {
+               $extra = json_decode($this->fields['extra_options'], true);
+               if (!empty($extra)) {
+                  $default = array_merge($default, $extra);
+               }
+            } catch (Exception $ex) {
+               
+            }
+         }
+         $options = array_merge($default, $options);
+
+         $this->_provider = self::createInstance($type, $options, $collaborators);
+      }
+      return $this->_provider;
+   }
+
+   /**
+    * 
+    * @return boolean|string
+    */
+   public function checkAuthorization() {
+      if ($this->_provider === null) {
+         return false;
+      }
+
+      if (!isset($_GET['code'])) {
+
+         $scope = [];
+         if (!empty($this->fields['scope'])) {
+            $scope = explode(',', $this->fields['scope']);
+         }
+
+         $options = [
+            'scope' => $scope,
+            'state' => Session::getNewCSRFToken(),
+         ];
+
+         $this->_provider->authorize($options);
+      }
+
+      // Check given state against previously stored one to mitigate CSRF attack
+      $state = isset($_GET['state']) ? $_GET['state'] : '';
+
+      Session::checkCSRF([
+         '_glpi_csrf_token' => $state,
+      ]);
+
+      $this->_code = $_GET['code'];
+
+      return $_GET['code'];
+   }
+
+   /**
+    * 
+    * @return boolean|\League\OAuth2\Client\Token\AccessToken
+    */
+   public function getAccessToken() {
+      if ($this->_token !== null) {
+         return $this->_token;
+      }
+
+      if ($this->_provider === null || $this->_code === null) {
+         return false;
+      }
+
+      $this->_token = $this->_provider->getAccessToken('authorization_code', [
+         'code' => $this->_code
+      ]);
+
+      return $this->_token;
+   }
+
+   /**
+    * 
+    * @return boolean|\League\OAuth2\Client\Provider\ResourceOwnerInterface
+    */
+   public function getResourceOwner() {
+      if ($this->_resource_owner !== null) {
+         return $this->_resource_owner;
+      }
+
+      $token = $this->getAccessToken();
+      if (!$token) {
+         return false;
+      }
+
+
+      $this->_resource_owner = $this->_provider->getResourceOwner($token);
+
+      return $this->_resource_owner;
+   }
+
+   public function findUser() {
+      $resource = $this->getResourceOwner();
+
+      $resource_array = $resource->toArray();
+
+      $user = new User();
+      //First: check linked user
+
+      $email = false;
+      $email_fields = ['email', 'e-mail'];
+
+      foreach ($email_fields as $field) {
+         if (isset($resource_array[$field]) && is_string($resource_array[$field])) {
+            $email = $resource_array[$field];
+            break;
+         }
+      }
+
+      if ($email && $user->getFromDBbyEmail($email, '')) {
+         return $user;
+      }
+
+      $login = false;
+      $login_fields = ['login', 'username'];
+
+      foreach ($login_fields as $field) {
+         if (isset($resource_array[$field]) && is_string($resource_array[$field])) {
+            $login = $resource_array[$field];
+            break;
+         }
+      }
+
+      if ($login && $user->getFromDBbyName($login)) {
+         return $user;
+      }
+
+      return false;
+   }
+
+   public function login() {
+      $user = $this->findUser();
+
+      if (!$user) {
+         return false;
+      }
+
+      //Create fake auth
+      $auth = new Auth();
+      $auth->user = $user;
+      $auth->auth_succeded = true;
+      $auth->extauth = 1;
+      $auth->user_present = $auth->user->getFromDBbyName(addslashes($user->fields['name']));
+      $auth->user->fields['authtype'] = Auth::DB_GLPI;
+
+      Session::init($auth);
+
+      return $auth->auth_succeded;
+   }
+
+}

+ 60 - 0
setup.php

@@ -0,0 +1,60 @@
+<?php
+
+define('PLUGIN_SINGLESIGNON_VERSION', '1.0.0');
+
+// Init the hooks of the plugins -Needed
+function plugin_init_singlesignon() {
+   global $PLUGIN_HOOKS, $CFG_GLPI, $CFG_SSO;
+
+   $autoload = __DIR__ . '/vendor/autoload.php';
+
+   if (file_exists($autoload)) {
+      include_once $autoload;
+   }
+
+   $PLUGIN_HOOKS['csrf_compliant']['singlesignon'] = true;
+
+   $CFG_SSO = Config::getConfigurationValues('singlesignon');
+
+   $PLUGIN_HOOKS['display_login']['singlesignon'] = "plugin_singlesignon_display_login";
+
+   $PLUGIN_HOOKS['menu_toadd']['singlesignon'] = [
+      'plugins' => 'PluginSinglesignonProvider',
+      'config'  => 'PluginSinglesignonProvider',
+   ];
+}
+
+// Get the name and the version of the plugin - Needed
+function plugin_version_singlesignon() {
+   return array(
+      'name'           => __sso('Single Sign-on'),
+      'version'        => PLUGIN_SINGLESIGNON_VERSION,
+      'author'         => 'Edgard Lorraine Messias',
+      'homepage'       => 'https://github.com/edgardmessias/glpi-singlesignon',
+      'minGlpiVersion' => '0.85'
+   );
+}
+
+// Optional : check prerequisites before install : may print errors or add to message after redirect
+function plugin_singlesignon_check_prerequisites() {
+   $autoload = __DIR__ . '/vendor/autoload.php';
+
+   if (!file_exists($autoload)) {
+      echo __sso("Run first: composer install");
+      return false;
+   }
+   if (version_compare(GLPI_VERSION, '0.85', 'lt')) {
+      echo __sso("This plugin requires GLPI >= 0.85");
+      return false;
+   } else {
+      return true;
+   }
+}
+
+function plugin_singlesignon_check_config() {
+   return true;
+}
+
+function __sso($str) {
+   return __($str, 'singlesignon');
+}