From de33cc78859925b2c1aacbf5c3f52bcd8eafa838 Mon Sep 17 00:00:00 2001
From: Alexandre Bourlier <alexandre@happy-dev.fr>
Date: Tue, 19 Jun 2018 23:59:50 +0200
Subject: [PATCH] Added OIDC client code

---
 README.md                            |  2 +-
 dist/lib/sib-oidc-client-config.json |  8 ++++++
 dist/lib/sib-oidc-client.js          | 41 ++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 dist/lib/sib-oidc-client-config.json
 create mode 100644 dist/lib/sib-oidc-client.js

diff --git a/README.md b/README.md
index 7516426e..3b36a27e 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ HD app is the magic tool that allows the Happy Dev network to thrive in a decent
   * `git clone --recurse-submodules https://git.happy-dev.fr/happy-dev/hd-app.git`
   * `cd hd-app`
   * `cp config-sample.php config.php`
-  * Edit `config.php` to suits your own setup
+  * Edit `config.php` to suit your own setup
   * `npm install -g grunt-cli`
   * `npm install`
 
diff --git a/dist/lib/sib-oidc-client-config.json b/dist/lib/sib-oidc-client-config.json
new file mode 100644
index 00000000..5c0cf624
--- /dev/null
+++ b/dist/lib/sib-oidc-client-config.json
@@ -0,0 +1,8 @@
+{
+  "authority": "http://localhost:8000/openid/",
+  "client_id": "598550",
+  "redirect_uri": "http://oidc-client.local/user-manager-sample.html",
+  "response_type": "id_token token",
+  "scope": "openid profile email",
+  "loadUserInfo": true
+}
diff --git a/dist/lib/sib-oidc-client.js b/dist/lib/sib-oidc-client.js
new file mode 100644
index 00000000..4cac849b
--- /dev/null
+++ b/dist/lib/sib-oidc-client.js
@@ -0,0 +1,41 @@
+if (typeof Oidc == "undefined") {
+  throw new Error("You are missing the `oidc-client-js` lib");
+}
+
+
+// Var declarations
+var sib  = {};
+sib.oidc = {};
+
+
+// Setup User Manager
+sib.oidc._setup = function(settings) {
+  if (typeof sib.oidc._manager == "undefined") {
+    sib.oidc._manager = new Oidc.UserManager(settings);
+  }
+}
+
+
+// Connect to OIDC provider
+sib.oidc.connect = function (settings) {
+  sib.oidc._setup(settings);
+
+  sib.oidc._manager.signinRedirectCallback()
+    .then()
+    .catch(function(error) {
+      console.log(error);
+
+      sib.oidc._manager.signinRedirect({state: "some data"})
+        .then()
+        .catch(function(error) {
+          console.log(error);
+        });
+  });
+}
+
+
+// Entry point 
+fetch("./oidc-client-config.json")
+  .then(response => response.json())
+  .then(settings => sib.oidc.connect(settings));
+
-- 
GitLab