/
pc_local_auth.go
37 lines (33 loc) · 1.06 KB
/
pc_local_auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package auth
import (
"encoding/json"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/trace"
"github.com/gokyle/hotp"
)
// TODO : apply encryption
func RequestHOTPforSignupToken(client *TunClient, signupToken string) ([]string, error) {
// User will scan QRcode, here we just loads the OTP generator
// right from the backend.
// TODO : we need encryption
out, err := client.PostJSON(apiEndpoint(PocketUserSignup, PocketSignupToken),
signupTokenReq{
SignupToken: signupToken,
})
if err != nil {
return nil, trace.Wrap(err)
}
var tokenPack signupTokenPack
if err := json.Unmarshal(out.Bytes(), &tokenPack); err != nil {
return nil, trace.Wrap(err)
}
otp, err := hotp.Unmarshal(tokenPack.SignupToken.Hotp)
if err != nil {
return nil, trace.Wrap(err)
}
hotpTokens := make([]string, defaults.HOTPFirstTokensRange)
for i := 0; i < defaults.HOTPFirstTokensRange; i++ {
hotpTokens[i] = otp.OTP()
}
return hotpTokens, nil
}