imported jwt module
This commit is contained in:
78
jwt/tokens.go
Normal file
78
jwt/tokens.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Token interface {
|
||||
GetJTI() uuid.UUID
|
||||
GetEXP() int64
|
||||
GetScope() string
|
||||
getDB() *sql.DB
|
||||
Revoke(context.Context) error
|
||||
}
|
||||
|
||||
// Access token
|
||||
type AccessToken struct {
|
||||
ISS string // Issuer, generally TrustedHost
|
||||
IAT int64 // Time issued at
|
||||
EXP int64 // Time expiring at
|
||||
TTL string // Time-to-live: "session" or "exp". Used with 'remember me'
|
||||
SUB int // Subject (user) ID
|
||||
JTI uuid.UUID // UUID-4 used for identifying blacklisted tokens
|
||||
Fresh int64 // Time freshness expiring at
|
||||
Scope string // Should be "access"
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
// Refresh token
|
||||
type RefreshToken struct {
|
||||
ISS string // Issuer, generally TrustedHost
|
||||
IAT int64 // Time issued at
|
||||
EXP int64 // Time expiring at
|
||||
TTL string // Time-to-live: "session" or "exp". Used with 'remember me'
|
||||
SUB int // Subject (user) ID
|
||||
JTI uuid.UUID // UUID-4 used for identifying blacklisted tokens
|
||||
Scope string // Should be "refresh"
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func (a AccessToken) GetJTI() uuid.UUID {
|
||||
return a.JTI
|
||||
}
|
||||
func (r RefreshToken) GetJTI() uuid.UUID {
|
||||
return r.JTI
|
||||
}
|
||||
func (a AccessToken) GetEXP() int64 {
|
||||
return a.EXP
|
||||
}
|
||||
func (r RefreshToken) GetEXP() int64 {
|
||||
return r.EXP
|
||||
}
|
||||
func (a AccessToken) GetScope() string {
|
||||
return a.Scope
|
||||
}
|
||||
func (r RefreshToken) GetScope() string {
|
||||
return r.Scope
|
||||
}
|
||||
func (a AccessToken) getDB() *sql.DB {
|
||||
return a.db
|
||||
}
|
||||
func (r RefreshToken) getDB() *sql.DB {
|
||||
return r.db
|
||||
}
|
||||
func (a AccessToken) Revoke(ctx context.Context) error {
|
||||
return revoke(ctx, a)
|
||||
}
|
||||
func (r RefreshToken) Revoke(ctx context.Context) error {
|
||||
return revoke(ctx, r)
|
||||
}
|
||||
func (a AccessToken) CheckNotRevoked(ctx context.Context) (bool, error) {
|
||||
return checkNotRevoked(ctx, a)
|
||||
}
|
||||
func (r RefreshToken) CheckNotRevoked(ctx context.Context) (bool, error) {
|
||||
return checkNotRevoked(ctx, r)
|
||||
}
|
||||
Reference in New Issue
Block a user