auth

Paddy 2015-06-29 Parent:37a42585660e

174:9e3ceddf29ad Go to Latest

auth/profile_verification.go

Use an environment variable to set the JWT secret. When setting up the authd server, populate the JWT secret using a JWT_SECRET environment variable. Incidentally, we also included the subscriptions scope, for testing purposes while creating code.secondbit.org/ducky/subscriptions. We now also log the port we're listening on, listen on all interfaces (instead of just 127.0.0.1), and changed the port to 9000 instead of 8080.

History
1 package auth
3 import (
4 "log"
5 "time"
7 "code.secondbit.org/events.hg"
8 )
10 const (
11 EventSystem = "authd"
12 EventModelLogin = "login"
13 EventActionSendVerification = "send_verification"
14 EventTopicLoginVerification = "login_verification"
15 )
17 type loginVerificationNotifier interface {
18 SendLoginVerification(login Login)
19 }
21 type stdoutNotifier struct{}
23 func NewStdoutNotifier() stdoutNotifier {
24 return stdoutNotifier{}
25 }
27 func (s stdoutNotifier) SendLoginVerification(login Login) {
28 log.Printf("Use \"%s\" as the verification code for \"%s\"\n", login.Verification, login.Value)
29 }
31 type nsqNotifier struct {
32 *events.NSQPublisher
33 }
35 func NewNSQNotifier(address string) (*nsqNotifier, error) {
36 p, err := events.NewNSQPublisher(EventSystem+"/"+Version, address)
37 return &nsqNotifier{p}, err
38 }
40 func (n *nsqNotifier) SendLoginVerification(login Login) {
41 evt := events.Event{
42 System: EventSystem,
43 Model: EventModelLogin,
44 ID: login.Value,
45 Action: EventActionSendVerification,
46 Timestamp: time.Now(),
47 Data: map[string]string{
48 "verification": login.Verification,
49 },
50 }
51 err := n.Publish(EventTopicLoginVerification, evt)
52 if err != nil {
53 log.Printf("Error sending event: %#+v\n", err)
54 }
55 }