auth

Paddy 2015-05-17 Parent:37a42585660e

173:b0d1b3e39fc8 Go to Latest

auth/profile_verification.go

Make client use our auth(n/z) scheme. Our auth(n/z) scheme can be loosely defined as "encrypted tokens that nginx transforms into headers" and "scopes for bypassing ACL". Our Go client, which is what we'll be using to have services communicate with each other, follows this paradigm now by auto-injecting the headers we'll need to identify ourselves. This will work behind our firewall, but will be useless for the rest of the world, which will need to go through the nginx bastion that can strip the headers and replace them with the headers appropriate to the token attached to the request. This did involve setting a static client ID as the client for our email_verification listener. Ideally, this would cause Client registration (using that ID) when the listener starts up, ignoring ErrClientAlreadyExists. I don't want to have to write the code that will allow us to bypass the Client ACL properly right now, though, so we're just going to have to remember to manually create that Client. Or not. I don't think it will do any harm (outside the OAuth flow) to be using a Client ID that doesn't actually point to a Client. I just think it'd be good for record-keeping purposes.

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