auth
auth/context.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.
1.1 --- a/context.go Sat Apr 11 14:39:51 2015 -0400 1.2 +++ b/context.go Sat Apr 11 15:37:41 2015 -0400 1.3 @@ -336,6 +336,15 @@ 1.4 return c.sessions.getSession(id) 1.5 } 1.6 1.7 +// TerminateSession sets the Session identified by the passed ID as inactive in the sessionStore assocated 1.8 +// with the Context. 1.9 +func (c Context) TerminateSession(id string) error { 1.10 + if c.sessions == nil { 1.11 + return ErrNoSessionStore 1.12 + } 1.13 + return c.sessions.terminateSession(id) 1.14 +} 1.15 + 1.16 // RemoveSession removes the Session identified by the passed ID from the sessionStore associated with 1.17 // the Context. 1.18 func (c Context) RemoveSession(id string) error {