refactor to improve database operability
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -23,12 +21,14 @@ type Token interface {
|
||||
|
||||
// Revoke adds this token to the blacklist, preventing future use.
|
||||
// Must be called within a database transaction context.
|
||||
Revoke(*sql.Tx) error
|
||||
// Accepts any transaction type that implements DBTransaction interface.
|
||||
Revoke(DBTransaction) error
|
||||
|
||||
// CheckNotRevoked verifies that this token has not been blacklisted.
|
||||
// Returns true if the token is valid, false if revoked.
|
||||
// Must be called within a database transaction context.
|
||||
CheckNotRevoked(*sql.Tx) (bool, error)
|
||||
// Accepts any transaction type that implements DBTransaction interface.
|
||||
CheckNotRevoked(DBTransaction) (bool, error)
|
||||
}
|
||||
|
||||
// AccessToken represents a JWT access token with all its claims.
|
||||
@@ -84,15 +84,15 @@ func (a AccessToken) GetScope() string {
|
||||
func (r RefreshToken) GetScope() string {
|
||||
return r.Scope
|
||||
}
|
||||
func (a AccessToken) Revoke(tx *sql.Tx) error {
|
||||
func (a AccessToken) Revoke(tx DBTransaction) error {
|
||||
return a.gen.revoke(tx, a)
|
||||
}
|
||||
func (r RefreshToken) Revoke(tx *sql.Tx) error {
|
||||
func (r RefreshToken) Revoke(tx DBTransaction) error {
|
||||
return r.gen.revoke(tx, r)
|
||||
}
|
||||
func (a AccessToken) CheckNotRevoked(tx *sql.Tx) (bool, error) {
|
||||
func (a AccessToken) CheckNotRevoked(tx DBTransaction) (bool, error) {
|
||||
return a.gen.checkNotRevoked(tx, a)
|
||||
}
|
||||
func (r RefreshToken) CheckNotRevoked(tx *sql.Tx) (bool, error) {
|
||||
func (r RefreshToken) CheckNotRevoked(tx DBTransaction) (bool, error) {
|
||||
return r.gen.checkNotRevoked(tx, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user