added blacklist storage interface
This commit is contained in:
parent
339d6de8bd
commit
4c14116a41
3 changed files with 92 additions and 23 deletions
40
blacklist.go
Normal file
40
blacklist.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2018 Marius Schellenberger
|
||||
|
||||
package jwt
|
||||
|
||||
// Blacklist is the blacklisting storage interface
|
||||
type Blacklist interface {
|
||||
Add(string, int64)
|
||||
Remove(string)
|
||||
Check(string) bool
|
||||
Map() MapBlacklist
|
||||
}
|
||||
|
||||
// MapBlacklist implements the Blacklist interface
|
||||
type MapBlacklist map[string]int64
|
||||
|
||||
// NewMapBlacklist
|
||||
func NewMapBlacklist() MapBlacklist {
|
||||
return make(MapBlacklist)
|
||||
}
|
||||
|
||||
// Add adds a new token signature with expiration time to the blacklist
|
||||
func (mb MapBlacklist) Add(sig string, exp int64) {
|
||||
mb[sig] = exp
|
||||
}
|
||||
|
||||
// Remove deletes a token signature from the blacklist
|
||||
func (mb MapBlacklist) Remove(sig string) {
|
||||
delete(mb, sig)
|
||||
}
|
||||
|
||||
// Check returns true if a token signature is blacklisted and false otherwise
|
||||
func (mb MapBlacklist) Check(sig string) (ok bool) {
|
||||
_, ok = mb[sig]
|
||||
return
|
||||
}
|
||||
|
||||
// Map returns the blacklist in the form of a iterable map structure for cleanup
|
||||
func (mb MapBlacklist) Map() MapBlacklist {
|
||||
return mb
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue