netbank: Support hardware token authentication.
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 2 Jun 2021 00:46:22 +0000 (02:46 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 2 Jun 2021 00:46:22 +0000 (02:46 +0200)
netbank

diff --git a/netbank b/netbank
index a1d3566..5e7c474 100755 (executable)
--- a/netbank
+++ b/netbank
@@ -59,18 +59,21 @@ def cmd_login(cmd, args):
         sys.exit(1)
     sess = sesstype.create()
     if args[0] == "bankid":
-        if len(args) < 2:
-            sys.stderr.write("usage: login bankid USER-ID\n")
-            sys.exit(1)
-        with auth.ttyconv() as conv:
-            try:
-                sess.auth_bankid(args[1], conv)
-            except auth.autherror as err:
-                sys.stderr.write("netbank: authentication failed: %s\n" % err)
-                sys.exit(1)
+        authfun = sess.auth_bankid
+    elif args[0] == "token":
+        authfun = sess.auth_token
     else:
         sys.stderr.write("netbank: %s: unknown authentication type\n" % (args[0]))
         sys.exit(1)
+    if len(args) < 2:
+        sys.stderr.write("usage: login bankid USER-ID\n")
+        sys.exit(1)
+    with auth.ttyconv() as conv:
+        try:
+            authfun(args[1], conv)
+        except auth.autherror as err:
+            sys.stderr.write("netbank: authentication failed: %s\n" % err)
+            sys.exit(1)
 commands["login"] = cmd_login
 
 @requiresess