caddysignature

package module
v0.0.0-...-f3075c1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 8 Imported by: 0

README

Caddy OLO Signature Authorization

Generates the OLO Authorization header required for server-to-server integration with OLO's Ordering API.

Details

OLO requires several headers to be sent on all requests - one of them being a meticulously formatted Authorization header. This module handles the following:

  • Adds the Authorization header to the request
  • Adds the Date header
  • Adds the X-Forwarded-For header *

The X-Forwarded-For header will only be added when not provided by the client. It's recommended for the client to provide the X-Forwarded-For header.


Configuration

olo_signature {
  client_id test
  client_secret test
}

You may need to specify ordering globally like so:

{
  order olo_signature first
}

Why This Exists

TLDR; OLO requires all requests originating from a web-based client to pass through a proxy - server-to-server.

OLO refers to this mode of authorization as Signature Authorization. See how the outbound Authorization header is generated here.

Headers

For readers to know they're in the right place, below is a regurgitation of OLO documentation for required headers. All of these are handled by this module.

Date

Current timestamp in RFC1123 format using a fixed GMT offset.

Authorization

Format - OloSignature {ClientId}:{Signature}

Signature (quasi-)pseudo-code:

components := []string{
  olo.ClientId,
	request.Method,
	request.Header.Get("Content-Type"),
	base64.StdEncoding.EncodeToString(sha256HashedBody),
	request.URL.RequestURI(),
	requestDate,
}

hmacSha256([]byte(strings.Join(components, "\n")))

signature = base64.StdEncoding.EncodeToString(encryptedComponents)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MD5

func MD5(s string) string

Types

type AuthSignature

type AuthSignature struct {

	// OLO client secret for signing the request details.
	//ClientSecret string `json:"client_secret,omitempty"`
	IgnoreUrls string `json:"ignore_urls,omitempty"`

	IgnoreArray map[string]string
	ClientSalt  map[string]string
}

OLO client credentials required for Signature Authorization header generation.

Authorization: AuthSignature {ClientId}:{Signature}

Signature is a Base64 encoded, signed hash of the following request components: Client ID HTTP Method Content-Type Base64 encoded, request body hash (SHA-256) Request URI Date in RFC1123 format

func (AuthSignature) CaddyModule

func (AuthSignature) CaddyModule() caddy.ModuleInfo

func (*AuthSignature) Provision

func (m *AuthSignature) Provision(ctx caddy.Context) error

func (AuthSignature) ServeHTTP

func (*AuthSignature) UnmarshalCaddyfile

func (m *AuthSignature) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

func (AuthSignature) Validate

func (m AuthSignature) Validate() error

Jump to

Keyboard shortcuts

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