Documentation ¶
Overview ¶
Example ¶
var ( privateKey, _ = rsa.GenerateKey(rand.Reader, 2048) api = iris.New() myJoseMiddleware = New(Config{ KeysGetter: func() (interface{}, interface{}, error) { return privateKey, &privateKey.PublicKey, nil }, }) ) securedPingHandler := func(ctx *iris.Context) { claimString := myJoseMiddleware.Get(ctx) response := Response{Text: "Iauthenticated " + string(claimString)} claim := Claim{} json.Unmarshal(claimString, &claim) fmt.Println("claim :", claim.Name) ctx.JSON(iris.StatusOK, response) } // assign middleware and callback api.Get("/secured/ping", myJoseMiddleware.Serve, securedPingHandler) e := api.Tester(nil) // Create a new token claim := Claim{Name: " with Jose"} token := myJoseMiddleware.NewTokenWithClaim(claim) e.GET("/secured/ping").WithHeader("Authorization", "Bearer "+token). Expect().Status(iris.StatusOK).Body(). Contains("Iauthenticated").Contains("with Jose")
Output: claim : with Jose
Index ¶
Examples ¶
Constants ¶
const (
//Default context key
DefaultContextKey = "jose"
)
Variables ¶
This section is empty.
Functions ¶
func FromAuthHeader ¶
------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------
TOKEN EXTRACTORS //
------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------ FromAuthHeader is a TokenExtractor that takes a given context and extracts the JWS or JWE from the Authorization header
Types ¶
type Config ¶
type Config struct { // The function that will return the private ans public key to decrypt and validate the JOSE // Default : nil KeysGetter KeyFunc // String representing the key management algorithm //default value: RSA_OAEP_256 KeyAlgorithm jose.KeyAlgorithm // the name of the property in the request where the user information // from the JOSE will be stored //default value: jose ContextKey string //The function that will be called when there's an error validation the token ErrorHandler errorHandler //A boolean indicating if the credentials are required or not //default value: false CredentialsOptional bool //A function that extract the jose from request // Default: FromAuthHeader ( i.e from Authorization header as bearer token ) Extractor TokenExtractor // Debug flag turns on debugging output // Default : false Debug bool //When set, all requests with the OPTIONS method will use authentication // if you enable this options, you should register youre route with iris.Options(...) also // Default : false EnableAuthOnOptions bool // Define the signature algorithm. //default : RS512 SignatureAlgorithm jose.SignatureAlgorithm // specify the encryption algorythm // Default : A256CBC_HS512 EncryptionAlgorithm jose.ContentEncryption }
Config is a struct for specifying configurations options for the iris_jose middleware
type KeyFunc ¶
type KeyFunc func() (interface{}, interface{}, error)
Callback function to supply the key for verification. Used by the Parse methodbut unverified Token. This allows one to use properties in the Header of the token to identify which key to use
type Middleware ¶
type Middleware struct {
Config Config
}
middleware
func (*Middleware) CheckToken ¶
func (m *Middleware) CheckToken(ctx *iris.Context) error
CheckToken main functionnality, checks for token
func (*Middleware) Get ¶
func (m *Middleware) Get(ctx *iris.Context) []byte
Get returns the user information for this client/request
func (*Middleware) NewTokenWithClaim ¶
func (m *Middleware) NewTokenWithClaim(claim interface{}) string
create a new token with the given claim and with given encrypt and signing algs
func (*Middleware) Serve ¶
func (m *Middleware) Serve(ctx *iris.Context)
Serve the middelware's action
type TokenExtractor ¶
Token Extractor is a function that takes a context as input and returns either a token or an error. An error should only be returned if an attemps to specify a token was found, but the information was somehow incorrectly formed. In the case where a token is simply not present, this should not be treated as an error
func FromFirst ¶
func FromFirst(extractors ...TokenExtractor) TokenExtractor
FromFirst returns a function that runs multiple token extractors and takes the first token it finds
func FromParameter ¶
func FromParameter(param string) TokenExtractor
FromParameter returns a function that extracts the token from the specified query string parameter