From d575901cc17fa24ac33ff1cec0038cdf66401965 Mon Sep 17 00:00:00 2001
From: h4i4nhnc <haianhnc@mirabo.com.vn>
Date: Thu, 16 Dec 2021 14:49:59 +0700
Subject: [PATCH] feat: add line login modules

---
 src/modules/line.js | 53 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 src/modules/line.js

diff --git a/src/modules/line.js b/src/modules/line.js
new file mode 100644
index 00000000..246502ce
--- /dev/null
+++ b/src/modules/line.js
@@ -0,0 +1,53 @@
+(function (hello) {
+
+  hello.init({
+    line: {
+      name: "line",
+      oauth: {
+        version: 2,
+        auth: "https://access.line.me/oauth2/v2.1/authorize",
+        grant: "https://api.line.me/oauth2/v2.1/token",
+        response_type: "code",
+        client_secret: process.env.LINE_CLIENT_SECRET,
+        scope: {
+          basic: "profile%20openid%20email", // https://developers.line.biz/en/docs/line-login/integrate-line-login/#scopes
+        },
+        state: Math.random(),
+        scope_map: {
+          basic: ["profile", "openid", "email"],
+        },
+      },
+
+      base: "https://access.line.me/oauth2/v2.1/",
+
+      get: {
+        me: function (p, callback) {
+          p.path = "https://api.line.me/v2/profile";
+          p.headers = {
+            Authorization: `Bearer ${p.authResponse.access_token}`,
+          };
+          callback("https://api.line.me/v2/profile");
+        },
+      },
+
+      login: function (p) {
+        // OAuth2 non-standard adjustments
+        p.qs.scope = "profile%20openid%20email";
+      },
+
+      wrap: {
+        me: function (o) {
+          if (o.userId) {
+            o.picture = o.thumbnail = o.pictureUrl;
+            o.id = o.userId;
+            o.name = o.displayName;
+          }
+
+          return o;
+        },
+      },
+
+      jsonp: false,
+    },
+  });
+})(hello);