auth

Paddy 2015-04-11 Parent:d103a598548c Child:581c60f8dd23

159:cf6c1f05eb21 Go to Latest

auth/config.go

Enable terminating sessions through the API. Add a terminateSession method to the sessionStore that sets the Active property of the Session to false. Create a Context.TerminateSession wrapper for the terminateSession method on the sessionStore. Add a Sessions property to our response type so we can return a []Session in API responses. Use the URL-safe encoding when base64 encoding our session ID and CSRFToken, so the ID can be passed in the URL and so our encodings are consistent. Add a TerminateSessionHandler function that will extract a Session ID from the request URL, authenticate the user, check that the authenticated user owns the session in question, and terminate the session. Add implementations for our new terminateSession method for the memstore and postgres types. Test both the memstore and postgres implementation of our terminateSession helper in session_test.go.

History
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 iterations int
28 secureCookie bool
29 }
31 // Init is a function that preps the Config object to be used for Context creation, setting variables
32 // that are determined at the beginning of program execution.
33 func (c *Config) Init() error {
34 scheme, ok := passphraseSchemes[CurPassphraseScheme]
35 if !ok {
36 return ErrInvalidPassphraseScheme
37 }
38 var err error
39 c.iterations, err = scheme.calculateIterations()
40 if err != nil {
41 return err
42 }
43 log.Printf("Generating passphrases with %d iterations...\n", c.iterations)
44 return nil
45 }