package
0.15.1
Repository: https://github.com/cisco-open/go-lanai.git
Documentation: pkg.go.dev

# README

JWT

The JWT package provides support for working with JSON Web Tokens. This includes encoding and decoding tokens, as well as signing and verifying the signature of tokens.

JWK Store

In order to sign token (during encoding) and verify token (during decoding), the JWT package requires a JWK store. The JWK store is responsible for providing the private and public keys used in the signing and verification process. These implementations of the JWK stores are provided:

  1. FileJwkStore
  2. RemoteJwkStore

For testing, we also provide

  1. SingleJwkStore - A JWK store that contains a randomly generated private key for the specified algorithm.
  2. StaticJwkStore - A JWK store that contains a static list of randomly generated private key for the specified algorithm.

FileJwkStore

This store is used to load JWKs from pem files. The file location is specified using configuration properties. This is the default store used in the authorization server configuration.

security:
  keys:
    my-key-name:
      id: my-key-id
      format: pem
      file: my-key-file.pem

The FileJwkStore will load all the keys under the security.keys property. The pem file under each key name can contain one or more keys. Key name is a way to categorize the key by usage. For example, you may want to have a different set of keys for signing and encryption.

If the pem file contains one key. The key id of the key will equal to the name of the key. In this example, if my-key-file.pem contains only one key. That key's key id will be my-key-name.

If the pem file contains multiple key. The key id of the key will either be based on the id property if it's provided. Or it will be generated based on elements of the public key. In this example, since id is provided, the key id will be my-key-id-1 and my-key-id-2 etc.

Key Rotation

The FileJwkStore supports key rotation. If the pem file contains multiple keys, the LoadByName will return the current key for that name. After Rotate is called, the current key will be moved to the next key in the pem file.

Supported Key Types

The FileJwkStore supports the following key types:

  • RSA: PKCS8 unencrypted format. Tradition encrypted and unencrypted format.
  • ECDSA: PKCS8 unencrypted format. Tradition encrypted and unencrypted format.
  • ED25519: PKCS8 unencrypted format.
  • HMAC: Custom unencrypted format.

See the testdata directory for examples of pem files and how to generate them using openssl.

Use HMAC Key with Caution

HMAC key is a symmetric key. This file store supports HMAC key. However, it should be used with caution. By default, the HMAC key is included in the jwks endpoint which is by default public. If you want to use HMAC key, you should secure the jwks endpoint in your application, or encrypt the jwks content by providing your own jwks implementation instead of the default one.

RemoteJwkStore

This store is used to load JWKs from a remote endpoint. It's usually used when your application needs to verify the jwt signature issued from an authorization server that publishes its public keys through its jwks endpoint.

# Functions

BindCryptoProperties create and bind CryptoProperties, with a optional prefix.
NewCryptoProperties create a CryptoProperties with default values.
No description provided by the author
NewJwk new Jwk with specified public key Supported public key types: - *rsa.PublicKey - *ecdsa.PublicKey - ed25519.PublicKey - []byte (MAC secret) - any key implementing: interface{ Equal(x crypto.PublicKey) bool }.
No description provided by the author
NewPrivateJwk new PrivateJwk with specified private key Supported private key types: - *rsa.PrivateKey - *ecdsa.PrivateKey - ed25519.PrivateKey - []byte (MAC secret) - any key implementing: interface{ Public() crypto.PublicKey Equal(x crypto.PrivateKey) bool }.
NewRemoteJwkStore creates a JwkStore that load JWK with public key from an external JWKSet endpoint.
No description provided by the author
NewSignedJwtEncoder create a JwtEncoder that sign JWT with provided method.
NewSingleJwkStore Deprecated: Use NewSingleJwkStoreWithOptions.
No description provided by the author
NewStaticJwkStore Deprecated: Use NewStaticJwkStoreWithOptions.
No description provided by the author
ParseJwk parse Jwk from JSON as specified in RFC 7517 and RFC 7518.
ParseJwtHeaders extract JWT's headers without verifying the token.
SignWithJwkStore is a SigningOptions that set JwkStore and key name to use when signing.
SignWithMethod is SigningOptions that specify the method to use.
VerifyWithJwkStore is a VerifyOptions that set JwkStore and default key name to use when verifying.
VerifyWithMethods is a VerifyOptions that specify all allowed signing method ("alg" header).

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
FileJwkStore implements JwkStore and JwkRotator This store uses load key files for public and private keys.
GenericJwk implements Jwk.
GenericPrivateJwk implements Jwk and PrivateJwk.
No description provided by the author
PlaintextJwtDecoder implements JwtEncoder.
No description provided by the author
RemoteJwkStore implements JwkStore and load JWK with public key from an external JWKSet endpoint.
SignedJwtDecoder implements JwtEncoder.
SignedJwtEncoder implements JwtEncoder.
No description provided by the author
SingleJwkStore implements JwkStore This store always returns single JWK if Kid matches, return error if not This store is majorly for testing.
StaticJwkStore implements JwkStore and JwkRotator This store uses "kid" as seed to generate PrivateJwk.
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
goland:noinspection GoNameStartsWithPackageName.
goland:noinspection GoNameStartsWithPackageName.
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author