Skip to content

Commit 375ec29

Browse files
committed
add: pkgen
1 parent de22979 commit 375ec29

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

passkey/cmd/pkgen.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"encoding/base32"
5+
"fmt"
6+
"os"
7+
"strconv"
8+
"strings"
9+
10+
"github.com/zxdev/server/passkey"
11+
)
12+
13+
func main() {
14+
var secret string
15+
var interval int
16+
17+
switch len(os.Args) {
18+
case 3:
19+
interval, _ = strconv.Atoi(os.Args[2])
20+
fallthrough
21+
case 2:
22+
secret = os.Args[1]
23+
default:
24+
fmt.Print("\nusage:\npasskey {secret} {interval}\n secret : a 32-character base32 encoded string\n interval : is n seconds (default 60s)\n\n")
25+
return
26+
}
27+
28+
_, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(strings.ToUpper(secret))
29+
if err != nil || len(secret) != 32 {
30+
fmt.Print("passkey:\n secret : requires a 32-character base32 encoded string value(A..Z,2..7)\n\n")
31+
return
32+
}
33+
34+
pkc := passkey.NewClient(secret)
35+
if interval > 0 {
36+
pkc.Interval(interval)
37+
}
38+
39+
fmt.Println(pkc.Current())
40+
41+
}

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The default configuration is ```http``` on ```localhost:1455```, however when a
2525

2626
* ```authkey``` is a simple user:pass based system and middleware with supporting management endpoints
2727
* ```passkey``` is an interval based rolling token generation system with middleware for machine-to-machine communication based on shared secret using RFC 4226 standards
28+
* For passkey manual api tesing a passkey generator ```go build passkey/cmd/pkgen.go``` is provided to obtain the current passkey which can be used from the shell ```curl -H token:$(./pkgen AW6TJVTYMAYJXLWFW2WWJ6D3Q5B2AY25) http://localhost:1455/demo``` for command line testing
2829

2930
See the example folder for working sample use cases
3031

@@ -89,3 +90,4 @@ Sample passkey access responses
8990

9091

9192

93+

0 commit comments

Comments
 (0)