auth

Paddy 2015-04-11 Parent:849f3820b164 Child:73e12d5a1124

162:6f473576c6ae Go to Latest

auth/context.go

Clean up sessions and tokens after Profile is deleted. Add a terminateSessionsByProfile method to our sessionStore to mark Sessions associated with a Profile as inactive. Implement memstore and postgres implementations of the terminateSessionsByProfile method. Add a TerminateSessionsByProfile wrapper method to Context. Add a revokeTokensByProfileID method to our tokenStore to mark Tokens associated with a Profile as revoked. Implement memstore and postgres implementation of the revokeTokensByProfileID method. Add a RevokeTokensByProfileID wrapper method to Context. Call our RevokeTokensByProfileID and TerminateSessionsByProfile methods after a Profile is deleted, to clean up the Tokens and Sessions associated with it.

History
     1.1 --- a/context.go	Sat Apr 11 17:58:15 2015 -0400
     1.2 +++ b/context.go	Sat Apr 11 19:07:26 2015 -0400
     1.3 @@ -328,6 +328,15 @@
     1.4  	return c.tokens.revokeToken(token, refresh)
     1.5  }
     1.6  
     1.7 +// RevokeTokensByProfileID revokes the Tokens associated with the Profile identified by the passed ID in
     1.8 +// the tokenStore associated with the Context.
     1.9 +func (c Context) RevokeTokensByProfileID(profileID uuid.ID) error {
    1.10 +	if c.tokens == nil {
    1.11 +		return ErrNoTokenStore
    1.12 +	}
    1.13 +	return c.tokens.revokeTokensByProfileID(profileID)
    1.14 +}
    1.15 +
    1.16  // GetTokensByProfileID returns a slice of up to num Tokens with a ProfileID that matches the specified
    1.17  // profileID from the tokenStore associated with the Context, skipping offset Tokens.
    1.18  func (c Context) GetTokensByProfileID(profileID uuid.ID, num, offset int) ([]Token, error) {
    1.19 @@ -362,6 +371,15 @@
    1.20  	return c.sessions.terminateSession(id)
    1.21  }
    1.22  
    1.23 +// TerminateSessionsByProfile sets the Sessions associated with the passed Profile ID as inactive in the
    1.24 +// sessionStore associated with the Context.
    1.25 +func (c Context) TerminateSessionsByProfile(profile uuid.ID) error {
    1.26 +	if c.sessions == nil {
    1.27 +		return ErrNoSessionStore
    1.28 +	}
    1.29 +	return c.sessions.terminateSessionsByProfile(profile)
    1.30 +}
    1.31 +
    1.32  // RemoveSession removes the Session identified by the passed ID from the sessionStore associated with
    1.33  // the Context.
    1.34  func (c Context) RemoveSession(id string) error {