Documentation
¶
Index ¶
- func GenRSKeys(keysize int) (*jose.JSONWebKey, *jose.JSONWebKey, error)
- type Issuer
- func (i Issuer) Authenticate(ctx context.Context, token string) (jwtauth.Claims, error)
- func (i Issuer) Authenticator() jwtauth.Authenticator
- func (i Issuer) HTTPAuth() *jwthttp.Auth
- func (i Issuer) Issue(claims jwtauth.Claims) (string, error)
- func (i Issuer) IssueFromMap(claims map[string]interface{}) (string, error)
- func (i Issuer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (i Issuer) Verify(token *jwt.JSONWebToken, claims ...interface{}) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenRSKeys ¶
func GenRSKeys(keysize int) (*jose.JSONWebKey, *jose.JSONWebKey, error)
GenRSKeys generates a public/private key pair for signing using RS256 algorithm.
Types ¶
type Issuer ¶
type Issuer struct {
jose.Signer
PubKey *jose.JSONWebKey
Name string
}
Issuer is a test issuer to issue jwts with claims on demand
Intended for easy testing. Use Issue to create a new jwt that can be authenticated by the public key
ServeHTTP serves the public key as a jwks payload.
func (Issuer) Authenticate ¶
Authenticate implements jwtauth.Authenticator
Checks the issuer on the inbound jwt matches the name of the issuer.
func (Issuer) Authenticator ¶
func (i Issuer) Authenticator() jwtauth.Authenticator
Authenticator produces a standard authenticator with only this issuer as a trusted issuer.
func (Issuer) HTTPAuth ¶
HTTPAuth returns an httpauth middleware struct with the issuer set as the authenticator.
func (Issuer) Issue ¶
Issue issues a new jwt with the given claims.
Example ¶
Shows how to use the issuer to issue a token with the desired claims.
package main
import (
"context"
"fmt"
"github.com/anz-bank/sysl-go/jwtauth"
"github.com/anz-bank/sysl-go/jwtauth/jwttest"
)
func main() {
ctx := context.Background()
issuer, _ := jwttest.NewIssuer("test", 1024)
token, _ := issuer.Issue(jwtauth.Claims{
"sub": "me",
"aud": []string{"target"},
"scope": "MY.SCOPE ANOTHER.SCOPE",
})
claims, _ := issuer.Authenticate(ctx, token)
fmt.Println("iss:", claims["iss"])
fmt.Println("sub:", claims["sub"])
fmt.Println("aud:", claims["aud"])
fmt.Println("scope:", claims["scope"])
}
Output: iss: test sub: me aud: [target] scope: MY.SCOPE ANOTHER.SCOPE
func (Issuer) IssueFromMap ¶
IssueFromMap issues a new jwt with the given claims.