auth

package
v0.0.0-...-1256ada Latest Latest
Warning

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

Go to latest
Published: May 25, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncryptAccessToken

func EncryptAccessToken(token *Token, encryptionKey interface{}) (string, error)

Encrypt the access token using 128 bit AES, with a shared key given in encryptionKey

func EncryptRefreshToken

func EncryptRefreshToken(token *Token, publicKey interface{}) (string, error)

Encrypt the refresh token using 2048 bit rsa key. publicKey should be &privateKey.PublicKey

func ValidateAccessToken

func ValidateAccessToken(check func(token *Token, ctx *gin.Context) bool, encryptionKey interface{}) gin.HandlerFunc

ValidateAccessToken extracts an access token from the headers, checks that it's valid and then passes it on to the check-function

Types

type Scope

type Scope struct {
	Roles        []string `json:"roles"`
	Capabilities []string `json:"capabilities"`
}

type Token

type Token struct {
	IssueTime int64  `json:"iat"`
	ID        string `json:"jti"`
	AccountID string `json:"sub"`
	Type      string `json:"type"`
	Scope     Scope  `json:"scope"`
}

func DecryptAccessToken

func DecryptAccessToken(token string, encryptionKey interface{}) (*Token, error)

Decrypt the access token in serialized form using 128 bit AES, with a shared key given in encryptionKey

func DecryptRefreshToken

func DecryptRefreshToken(token string, privateKey interface{}) (*Token, error)

Decrypt the refresh token in serialized form using 2048 bit rsa key. privateKey should be &privateKey

func (*Token) HasCapability

func (token *Token) HasCapability(capability string) bool

HasCapability checks if the access token contains the given capability

func (*Token) HasRole

func (token *Token) HasRole(role string) bool

HasRole checks if the access token contains the given role

func (*Token) Valid

func (token *Token) Valid() bool

Valid validates the access token based on the issue time and expire time (TBD)

Jump to

Keyboard shortcuts

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