auth

Paddy 2015-04-11 Parent:762953f6a7f2 Child:73e12d5a1124

162:6f473576c6ae Go to Latest

auth/token.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/token.go	Sat Apr 11 17:58:15 2015 -0400
     1.2 +++ b/token.go	Sat Apr 11 19:07:26 2015 -0400
     1.3 @@ -55,6 +55,7 @@
     1.4  	saveToken(token Token) error
     1.5  	revokeToken(token string, refresh bool) error
     1.6  	getTokensByProfileID(profileID uuid.ID, num, offset int) ([]Token, error)
     1.7 +	revokeTokensByProfileID(profileID uuid.ID) error
     1.8  }
     1.9  
    1.10  func (m *memstore) getToken(token string, refresh bool) (Token, error) {
    1.11 @@ -116,6 +117,22 @@
    1.12  	return nil
    1.13  }
    1.14  
    1.15 +func (m *memstore) revokeTokensByProfileID(profileID uuid.ID) error {
    1.16 +	ids, err := m.lookupTokensByProfileID(profileID.String())
    1.17 +	if err != nil {
    1.18 +		return err
    1.19 +	}
    1.20 +	if len(ids) < 1 {
    1.21 +		return ErrProfileNotFound
    1.22 +	}
    1.23 +	m.tokenLock.Lock()
    1.24 +	defer m.tokenLock.Unlock()
    1.25 +	for _, id := range ids {
    1.26 +		delete(m.tokens, id)
    1.27 +	}
    1.28 +	return nil
    1.29 +}
    1.30 +
    1.31  func (m *memstore) getTokensByProfileID(profileID uuid.ID, num, offset int) ([]Token, error) {
    1.32  	ids, err := m.lookupTokensByProfileID(profileID.String())
    1.33  	if err != nil {