auth

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

160:48200d8c4036 Go to Latest

auth/config.go

Start to support deleting profiles through the API. Create a removeLoginsByProfile method on the profileStore, to allow an easy way to bulk-delete logins associated with a Profile after the Profile has been deleted. Create postgres and memstore implementations of the removeLoginsByProfile method. Create a cleanUpAfterProfileDeletion helper method that will clean up the child objects of a Profile (its Sessions, Tokens, Clients, etc.). The intended usage is to call this in a goroutine after a Profile has been deleted, to try and get things back in order. Detect when the UpdateProfileHandler API is used to set the Deleted flag of a Profile to true, and clean up after the Profile when that's the case. Add a DeleteProfileHandler API endpoint that is a shortcut to setting the Deleted flag of a Profile to true and cleaning up after the Profile. The problem with our approach thus far is that some of it is reversible and some is not. If a Profile is maliciously/accidentally deleted, it's simple enough to use the API as a superuser to restore the Profile. But doing that will not (and cannot) restore the Logins associated with that Profile, for example. While it would be nice to add a Deleted flag to our Logins that we could simply toggle, that would wreak havoc with our database constraints and ensuring uniqueness of Login values. I still don't have a solution for this, outside the superuser manually restoring a Login for the Profile, after which the user can authenticate themselves and add more Logins as desired. But there has to be a better way. I suppose since the passphrase is being stored with the Profile and not the Login, we could offer an endpoint that would automate this, but... well, that would be tricky. It would require the user remembering their Profile ID, and let's be honest, nobody's going to remember a UUID. Maybe such an endpoint would help from a customer service standpoint: we identify their Profile manually, then send them to /profiles/ID/restorelogin or something, and that lets them add a Login back to the Profile. I'll figure it out later. For now, we know we at least have enough information to identify a user is who they say they are and resolve the situation manually.

History
paddy@96 1 package auth
paddy@96 2
paddy@96 3 import (
paddy@96 4 "errors"
paddy@96 5 "html/template"
paddy@101 6 "log"
paddy@96 7 )
paddy@96 8
paddy@96 9 var (
paddy@96 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.
paddy@96 11 ErrInvalidLoginURI = errors.New("invalid login URI")
paddy@102 12 // ErrConfigNotInitialized is returned when a Context is instantiated with a Config object that hasn't had its Init function called.
paddy@102 13 ErrConfigNotInitialized = errors.New("config not initialized")
paddy@96 14 )
paddy@96 15
paddy@96 16 // Config holds the configuration values necessary to run a server. A Config
paddy@96 17 // instance is the only way to instantiate a Context variable.
paddy@96 18 type Config struct {
paddy@96 19 ClientStore clientStore
paddy@96 20 AuthCodeStore authorizationCodeStore
paddy@96 21 ProfileStore profileStore
paddy@96 22 TokenStore tokenStore
paddy@96 23 SessionStore sessionStore
paddy@134 24 ScopeStore scopeStore
paddy@96 25 Template *template.Template
paddy@96 26 LoginURI string
paddy@96 27 iterations int
paddy@132 28 secureCookie bool
paddy@96 29 }
paddy@101 30
paddy@102 31 // Init is a function that preps the Config object to be used for Context creation, setting variables
paddy@102 32 // that are determined at the beginning of program execution.
paddy@101 33 func (c *Config) Init() error {
paddy@101 34 scheme, ok := passphraseSchemes[CurPassphraseScheme]
paddy@101 35 if !ok {
paddy@101 36 return ErrInvalidPassphraseScheme
paddy@101 37 }
paddy@101 38 var err error
paddy@101 39 c.iterations, err = scheme.calculateIterations()
paddy@101 40 if err != nil {
paddy@101 41 return err
paddy@101 42 }
paddy@101 43 log.Printf("Generating passphrases with %d iterations...\n", c.iterations)
paddy@101 44 return nil
paddy@101 45 }