Skip to content

Commit

Permalink
Hash oAuth tokens in redis (TykTechnologies#2176)
Browse files Browse the repository at this point in the history
Added backward compatibility with unhashed version

Fix TykTechnologies#2158
  • Loading branch information
buger committed Mar 18, 2019
1 parent 241fd01 commit dede565
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions oauth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func (r *RedisOsinStorageInterface) SaveAccess(accessData *osin.AccessData) erro
return err
}

key := prefixAccess + accessData.AccessToken
key := prefixAccess + storage.HashKey(accessData.AccessToken)
log.Debug("Saving ACCESS key: ", key)

// Overide default ExpiresIn:
Expand Down Expand Up @@ -745,13 +745,19 @@ func (r *RedisOsinStorageInterface) SaveAccess(accessData *osin.AccessData) erro

// LoadAccess will load access data from redis
func (r *RedisOsinStorageInterface) LoadAccess(token string) (*osin.AccessData, error) {
key := prefixAccess + token
key := prefixAccess + storage.HashKey(token)
log.Debug("Loading ACCESS key: ", key)
accessJSON, err := r.store.GetKey(key)

if err != nil {
log.Error("Failure retreiving access token by key: ", err)
return nil, err
// Fallback to unhashed value for backward compatibility
key = prefixAccess + token
accessJSON, err = r.store.GetKey(key)

if err != nil {
log.Error("Failure retreiving access token by key: ", err)
return nil, err
}
}

accessData := osin.AccessData{Client: new(OAuthClient)}
Expand Down

0 comments on commit dede565

Please sign in to comment.