jwt

package
v0.0.0-...-8d8ec1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package jwt -

Package jwt - JWT 관련 기능을 제공하는 패키지

Package jwt -

Package jwt -

Package jwt -

Package jwt -

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSigningMethodMismatch - 다른 서명 메서드가 적용된 경우 오류
	ErrSigningMethodMismatch = errors.New("signing method mismatch")
	// ErrFailedToParseToken - 비밀키와 만기등을 검증하기 위한 파싱 처리에 실패한 경우 오류
	ErrFailedToParseToken = errors.New("failed to parse token")
	// ErrUnsupportedSigningMethod - 지원되지 않는 서명 메서드인 경우 오류
	ErrUnsupportedSigningMethod = errors.New("unsupported signing method")
	// ErrInvalidPEMBlock - PEM-encoded 가 아닌 키 구성인 경우 오류
	ErrInvalidPEMBlock = errors.New("invalid RSA: not PEM-encoded")
	// ErrNotRSAPublicKey - RSA 공개 키 형식이 아닌 경우 오류
	ErrNotRSAPublicKey = errors.New("invalid RSA: expected PUBLIC KEY block type")
	// ErrBadPublicKey - RSA 공개 키가 잘못된 경우 오류
	ErrBadPublicKey = errors.New("invalid RSA: failed to assert public key")
)

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Type    string `yaml:"token_type" json:"token_type"`
	Token   string `yaml:"access_token" json:"access_token"`
	Expires int64  `yaml:"expires_in" json:"expires_in"`
}

AccessToken - Token 정보 구조

func IssueAdminToken

func IssueAdminToken(signingMethod SigningMethod, claims jwt.MapClaims, expireIn time.Duration) (*AccessToken, error)

IssueAdminToken - API 접근을 위한 ADMIN JWT 발급

type AppClaims

type AppClaims struct {
	jwt.MapClaims
	// contains filtered or unexported fields
}

AppClaims - JWT 검증을 위한 Claim 처리 구조

func NewAppClaims

func NewAppClaims(leeway int64) *AppClaims

NewAppClaims - ADMIN 에서 사용할 Claims 생성

func (*AppClaims) UnmarshalJSON

func (ac *AppClaims) UnmarshalJSON(text []byte) error

UnmarshalJSON - AppClaims에 대한 Claims를 unmarshal 처리

func (*AppClaims) Valid

func (ac *AppClaims) Valid() error

Valid - 현재는 시간정보(exp, iat, nbf, ...Valid)를 기준으로 하며, 이런 정보가 없다고 해도 Valid 한 것으로 처리

func (*AppClaims) VerifyExpiresAt

func (ac *AppClaims) VerifyExpiresAt(cmp int64, req bool) bool

VerifyExpiresAt - 만기여부와 Leeway 검증을 위해 jwt.StandardClaims.VerifyExpiresAt() 재 정의

func (*AppClaims) VerifyIssuedAt

func (ac *AppClaims) VerifyIssuedAt(cmp int64, req bool) bool

VerifyIssuedAt - 발금과 Leeway 검증을 위해 jwt.StandardClaims.VerifyIssuedAt() 재 정의

func (*AppClaims) VerifyNotBefore

func (ac *AppClaims) VerifyNotBefore(cmp int64, req bool) bool

VerifyNotBefore 검증여부와 Leeway 검증을 위해 jwt.StandardClaims.VerifyNotBefore() 재 정의

type Guard

type Guard struct {
	ParserConfig
	// JWT 인증 유효 시간 (기본값: 1h)
	Timeout time.Duration
	// 신규 토큰 서명을 정보 (알고리즘/키페어)
	SigningMethod SigningMethod
	// 최대 갱신 시간(기본값: 24h, 0 - 갱신하지 않음)
	MaxRefresh time.Duration
}

Guard - JWT 인증 기반 구조

func NewGuard

func NewGuard(cc *config.CredentialsConfig) Guard

NewGuard - 지정한 정보를 기준으로 인증 처리기 생성

type Handler

type Handler struct {
	Guard Guard
}

Handler - JWT 처리와 연계되는 구조

func (*Handler) Login

Login - JWT Token 기반으로 인증 처리

func (*Handler) Logout

Logout - JWT Token 기반으로 인증 해제 처리

func (*Handler) Refresh

func (h *Handler) Refresh() http.HandlerFunc

Refresh - 현재 JWT에 대한 Refresh 처리

type Middleware

type Middleware struct {
	Guard Guard
}

Middleware - JWT Middleware 설정 구조

func NewMiddleware

func NewMiddleware(g Guard) *Middleware

NewMiddleware - JWT 관련 Middleware 구성

func (*Middleware) Handler

func (m *Middleware) Handler(h http.Handler) http.HandlerFunc

Handler - Request 핸들러 처리

type Parser

type Parser struct {
	Config ParserConfig
}

Parser - Parser 설정 관리 구조

func (*Parser) Parse

func (p *Parser) Parse(tokenString string) (*jwt.Token, error)

Parse a JWT token and validates it

func (*Parser) ParseFromRequest

func (p *Parser) ParseFromRequest(req *http.Request) (*jwt.Token, error)

ParseFromRequest - Request에서 Token 추출 및 검증

type ParserConfig

type ParserConfig struct {
	SigningMethods []SigningMethod
	// Request 정보에서 토큰 추출을 위한 정보 "<source>:<name>" 형식 (ex. "header:Authorization", "query:name", "cookie:name")
	TokenLookup string
	// 만기 시간용
	Leeway int64
}

ParserConfig - JWT 파서 및 토큰 검증 구조

type Payload

type Payload struct{}

Payload - JWT 연관 Context Key 구조

type SigningMethod

type SigningMethod struct {
	// 알고리즘 (HS256, HS384, HS512, RS256, RS384, RS512)
	Alg string `yaml:"alg" json:"alg"`
	Key string `yaml:"key" json:"key"`
}

SigningMethod - 서명 처리에 필요한 알고리즘, 키 구조

type User

type User struct {
	Username string
	Email    string
}

User - 사용자 정보 구조

Directories

Path Synopsis
Package basic - Package basic - BASIC Auth 기능 제공 패키지
Package basic - Package basic - BASIC Auth 기능 제공 패키지
Package provider - JWT Provider 기능 제공 패키지 Package provider -
Package provider - JWT Provider 기능 제공 패키지 Package provider -

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL