From 2308e485ec479dd120baf4496b839612eb96aaa0 Mon Sep 17 00:00:00 2001 From: kotontrion Date: Sun, 19 May 2024 19:15:09 +0200 Subject: add: Readme and gjs examples --- examples/full_example.js | 38 ++++++++++++++++++++++++++++++++++++++ examples/simple_example.js | 9 +++++++++ 2 files changed, 47 insertions(+) create mode 100644 examples/full_example.js create mode 100644 examples/simple_example.js (limited to 'examples') diff --git a/examples/full_example.js b/examples/full_example.js new file mode 100644 index 0000000..7359784 --- /dev/null +++ b/examples/full_example.js @@ -0,0 +1,38 @@ +#!/usr/bin/env -S gjs -m + +import Auth from "gi://AstalAuth"; +import GLib from "gi://GLib"; + +const loop = GLib.MainLoop.new(null, false); + +const pam = new Auth.Pam(); +pam.connect("auth-prompt-visible", (p, msg) => { + print(msg); + p.supply_secret(""); +}); +pam.connect("auth-prompt-hidden", (p, msg) => { + print(msg); + p.supply_secret("password"); +}); +pam.connect("auth-info", (p, msg) => { + print(msg); + p.supply_secret(""); +}); +pam.connect("auth-error", (p, msg) => { + print(msg); + p.supply_secret(""); +}); + +pam.connect("success", p => { + print("authentication sucessful"); + loop.quit(); +}); +pam.connect("fail", (p, msg) => { + print(msg); + loop.quit(); +}); + +pam.start_authenticate(); + +loop.runAsync() + diff --git a/examples/simple_example.js b/examples/simple_example.js new file mode 100644 index 0000000..2bf38c1 --- /dev/null +++ b/examples/simple_example.js @@ -0,0 +1,9 @@ +#!/usr/bin/env -S gjs -m +import Auth from "gi://AstalAuth"; +import Gio from "gi://Gio"; + +Gio._promisify(Auth.Pam, "authenticate"); + +await Auth.Pam.authenticate("password") + .then(_ => print("authentication sucessful")) + .catch(logError); \ No newline at end of file -- cgit v1.2.3