middleware

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Example
package main

import (
	"io"
	"log"
	"net/http"

	"github.com/heroku/x/dynoid/middleware"
)

const Audience = "testing"

func main() {
	authorized := middleware.AuthorizeSameSpace(Audience)
	secureHandler := authorized(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
		if _, err := io.WriteString(w, "Hello from a secure endpoint!\n"); err != nil {
			log.Printf("error writing response (%v)", err)
		}
	}))

	http.Handle("/secure", secureHandler)

	log.Fatal(http.ListenAndServe(":8080", nil))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// returned when the `Authorization` header does not contain a Bearer token
	ErrTokenMissing = errors.New("token not found")
)

Functions

func Authorize

func Authorize(audience string, callback dynoid.IssuerCallback) func(http.Handler) http.Handler

Authorize populates the dyno identity blocks requests where the callback fails.

func AuthorizeSameSpace

func AuthorizeSameSpace(audience string) func(http.Handler) http.Handler

AuthorizeSameSpace restricts access to tokens from the same space/issuer for the given audience.

func AuthorizeSpaces

func AuthorizeSpaces(audience string, spaces ...string) func(http.Handler) http.Handler

AuthorizeSpaces populates the dyno identity and blocks any requests that aren't from one of the given spaces.

func AuthorizeSpacesWithIssuer added in v0.4.0

func AuthorizeSpacesWithIssuer(audience, issuer string, spaces ...string) func(http.Handler) http.Handler

AuthorizeSpacesWithIssuer populates the dyno identity and blocks any requests that aren't from one of the given spaces and issuer.

func Populate

func Populate(audience string, callback dynoid.IssuerCallback) func(http.Handler) http.Handler

Populate attempts to validate and parse a Token from the request for the given audience but doesn't enforce any restrictions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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