auth

Paddy 2014-12-14 Parent:9c50b2e2e03b Child:267483f168b5

96:e57a57a944c4 Go to Latest

auth/context.go

Introduce Config and NewContext. Config is an exported struct that configures the program. It holds all the values that a Context needs. NewContext takes a Config object and builds a Context out of it.

History
     1.1 --- a/context.go	Sat Dec 13 19:45:38 2014 -0500
     1.2 +++ b/context.go	Sun Dec 14 11:59:46 2014 -0500
     1.3 @@ -21,6 +21,28 @@
     1.4  	profiles  profileStore
     1.5  	tokens    tokenStore
     1.6  	sessions  sessionStore
     1.7 +	config    Config
     1.8 +}
     1.9 +
    1.10 +// NewContext takes a Config instance and uses it to bootstrap a Context
    1.11 +// using the information provided in the Config variable.
    1.12 +func NewContext(config Config) (Context, error) {
    1.13 +	context := Context{
    1.14 +		clients:   config.ClientStore,
    1.15 +		authCodes: config.AuthCodeStore,
    1.16 +		profiles:  config.ProfileStore,
    1.17 +		tokens:    config.TokenStore,
    1.18 +		sessions:  config.SessionStore,
    1.19 +		template:  config.Template,
    1.20 +		config:    config,
    1.21 +	}
    1.22 +	var err error
    1.23 +	context.loginURI, err = url.Parse(config.LoginURI)
    1.24 +	if err != nil {
    1.25 +		log.Println(err)
    1.26 +		return Context{}, ErrInvalidLoginURI
    1.27 +	}
    1.28 +	return context, nil
    1.29  }
    1.30  
    1.31  // Render uses the HTML templates associated with the Context to render the