auth

Paddy 2015-07-18 Parent:0a2c3d677161 Child:b7e685839a1b

179:7bba108d2d9a Go to Latest

auth/config.go

Send events when logins are verified. Add an ActionLoginVerified constant to use as the action when a login has been verified. On second thought, this should probably just be "verified", huh? Then we can reuse it across models. Oops. We also added a call to send a login verified event to NSQ when the login is verified.

History
1 package auth
3 import (
4 "errors"
5 "html/template"
6 "log"
8 "code.secondbit.org/events.hg"
9 )
11 var (
12 // ErrInvalidLoginURI is returned when a Context is instantiated with a Config object that specifies a LoginURI that can't be parsed as a URL.
13 ErrInvalidLoginURI = errors.New("invalid login URI")
14 // ErrConfigNotInitialized is returned when a Context is instantiated with a Config object that hasn't had its Init function called.
15 ErrConfigNotInitialized = errors.New("config not initialized")
17 // Version is used to keep track of what version of the build this is
18 Version string
19 )
21 // Config holds the configuration values necessary to run a server. A Config
22 // instance is the only way to instantiate a Context variable.
23 type Config struct {
24 ClientStore clientStore
25 AuthCodeStore authorizationCodeStore
26 ProfileStore profileStore
27 TokenStore tokenStore
28 SessionStore sessionStore
29 ScopeStore scopeStore
30 EventsPublisher events.Publisher
31 Template *template.Template
32 LoginURI string
33 JWTPrivateKey []byte
34 iterations int
35 secureCookie bool
36 }
38 // Init is a function that preps the Config object to be used for Context creation, setting variables
39 // that are determined at the beginning of program execution.
40 func (c *Config) Init() error {
41 scheme, ok := passphraseSchemes[CurPassphraseScheme]
42 if !ok {
43 return ErrInvalidPassphraseScheme
44 }
45 var err error
46 c.iterations, err = scheme.calculateIterations()
47 if err != nil {
48 return err
49 }
50 log.Printf("Generating passphrases with %d iterations...\n", c.iterations)
51 return nil
52 }