auth

Paddy 2014-08-13 Parent:10b84165df41 Child:9a1e62c24903

10:244ac84003b3 Browse Files

Add logging. Log errors when obtaining and saving access tokens.

access.go context.go

     1.1 --- a/access.go	Wed Aug 13 06:46:13 2014 -0400
     1.2 +++ b/access.go	Wed Aug 13 07:04:23 2014 -0400
     1.3 @@ -319,15 +319,17 @@
     1.4  	// save access token
     1.5  	err = ctx.Tokens.SaveAccess(*data)
     1.6  	if err != nil {
     1.7 -		// TODO: log error
     1.8 +		if ctx.Log != nil {
     1.9 +			ctx.Log.Printf("Error writing access token: %s\n", err)
    1.10 +		}
    1.11  		return InternalServerError
    1.12  	}
    1.13  
    1.14  	// remove authorization token
    1.15  	if data.PreviousAuthorizeData != nil {
    1.16  		err = ctx.Tokens.RemoveAuthorization(data.PreviousAuthorizeData.Code)
    1.17 -		if err != nil {
    1.18 -			// TODO: log error
    1.19 +		if err != nil && ctx.Log != nil {
    1.20 +			ctx.Log.Printf("Error removing previous auth data (%s): %s\n", data.PreviousAuthorizeData.Code, err)
    1.21  		}
    1.22  	}
    1.23  
    1.24 @@ -335,13 +337,13 @@
    1.25  	if data.PreviousAccessData != nil {
    1.26  		if data.PreviousAccessData.RefreshToken != "" {
    1.27  			err = ctx.Tokens.RemoveRefresh(data.PreviousAccessData.RefreshToken)
    1.28 -			if err != nil {
    1.29 -				// TODO: log error
    1.30 +			if err != nil && ctx.Log != nil {
    1.31 +				ctx.Log.Printf("Error removing previous refresh token (%s): %s\n", data.PreviousAccessData.RefreshToken, err)
    1.32  			}
    1.33  		}
    1.34  		err = ctx.Tokens.RemoveAccess(data.PreviousAccessData.AccessToken)
    1.35 -		if err != nil {
    1.36 -			// TODO: log error
    1.37 +		if err != nil && ctx.Log != nil {
    1.38 +			ctx.Log.Printf("Error removing previous access token (%s): %s\n", data.PreviousAccessData.AccessToken, err)
    1.39  		}
    1.40  	}
    1.41  
    1.42 @@ -393,7 +395,9 @@
    1.43  		if err == ClientNotFoundError {
    1.44  			return Client{}, err
    1.45  		}
    1.46 -		// TODO: log error
    1.47 +		if ctx.Log != nil {
    1.48 +			ctx.Log.Printf("Error retrieving client %s: %s", id, err)
    1.49 +		}
    1.50  		return Client{}, InternalServerError
    1.51  	}
    1.52  	if client.Secret != auth.Password {
     2.1 --- a/context.go	Wed Aug 13 06:46:13 2014 -0400
     2.2 +++ b/context.go	Wed Aug 13 07:04:23 2014 -0400
     2.3 @@ -1,12 +1,16 @@
     2.4  package auth
     2.5  
     2.6 -import "io"
     2.7 +import (
     2.8 +	"io"
     2.9 +	"log"
    2.10 +)
    2.11  
    2.12  type Context struct {
    2.13  	Config   ServerConfig
    2.14  	Clients  ClientStore
    2.15  	Tokens   TokenStore
    2.16  	Profiles ProfileStore
    2.17 +	Log      *log.Logger
    2.18  }
    2.19  
    2.20  func (c Context) RenderError(w io.Writer, err error) {