40 lines
947 B
Go
40 lines
947 B
Go
// 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
|
|
}
|