auth
auth/config.go
Create interfaces for login verification flow. We needed an interface that we could use to say "send the email to verify the user's login" so that we could verify the emails we have are actually valid. This implements an NSQ version that sends an email_verification event. We'll get listener implementations that pull these messages off NSQ and actually send the emails. This also implements, for testing purposes, a version that just echoes the Login Value and the Verification code to stdout.
1 package auth
3 import (
4 "errors"
5 "html/template"
6 "log"
7 )
9 var (
10 // ErrInvalidLoginURI is returned when a Context is instantiated with a Config object that specifies a LoginURI that can't be parsed as a URL.
11 ErrInvalidLoginURI = errors.New("invalid login URI")
12 // ErrConfigNotInitialized is returned when a Context is instantiated with a Config object that hasn't had its Init function called.
13 ErrConfigNotInitialized = errors.New("config not initialized")
14 )
16 // Config holds the configuration values necessary to run a server. A Config
17 // instance is the only way to instantiate a Context variable.
18 type Config struct {
19 ClientStore clientStore
20 AuthCodeStore authorizationCodeStore
21 ProfileStore profileStore
22 TokenStore tokenStore
23 SessionStore sessionStore
24 ScopeStore scopeStore
25 Template *template.Template
26 LoginURI string
27 JWTPrivateKey []byte
28 iterations int
29 secureCookie bool
30 }
32 // Init is a function that preps the Config object to be used for Context creation, setting variables
33 // that are determined at the beginning of program execution.
34 func (c *Config) Init() error {
35 scheme, ok := passphraseSchemes[CurPassphraseScheme]
36 if !ok {
37 return ErrInvalidPassphraseScheme
38 }
39 var err error
40 c.iterations, err = scheme.calculateIterations()
41 if err != nil {
42 return err
43 }
44 log.Printf("Generating passphrases with %d iterations...\n", c.iterations)
45 return nil
46 }