Merge pull request #362 from RichardScothern/username-context

Add username to context
This commit is contained in:
Stephen Day 2015-04-15 12:26:26 -07:00
commit 030006a6d7
2 changed files with 4 additions and 2 deletions

View file

@ -66,7 +66,7 @@ func (ac *accessController) Authorized(ctx context.Context, accessRecords ...aut
return nil, &challenge
}
return context.WithValue(ctx, "auth.user", auth.UserInfo{Name: "silly"}), nil
return auth.WithUser(ctx, auth.UserInfo{Name: "silly"}), nil
}
type challenge struct {

View file

@ -324,6 +324,9 @@ func (app *App) dispatcher(dispatch dispatchFunc) http.Handler {
return
}
// Add username to request logging
context.Context = ctxu.WithLogger(context.Context, ctxu.GetLogger(context.Context, "auth.user.name"))
if app.nameRequired(r) {
repository, err := app.registry.Repository(context, getName(context))
@ -456,7 +459,6 @@ func (app *App) authorized(w http.ResponseWriter, r *http.Request, context *Cont
// should be replaced by another, rather than replacing the context on a
// mutable object.
context.Context = ctx
return nil
}