HTTP authentication middleware supporting multiple schemes
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
_examples
.editorconfig
.gitignore
.travis.yml
History.md
LICENSE
README.md
auth.go
auth_test.go
basic.go
basic_test.go
version.go

README.md

auth Build Status GoDoc Coverage Status Go Report Card

Simple HTTP authentication middleware, supporting Basic, Bearer, token and other authentication schemes.

Installation

go get -u gopkg.in/vinxi/auth.v0

API

See godoc reference.

Examples

Unique basic user auth

package main

import (
  "fmt"
  "gopkg.in/vinxi/auth.v0"
  "gopkg.in/vinxi/vinxi.v0"
)

const port = 3100

func main() {
  // Create a new vinxi proxy
  vs := vinxi.NewServer(vinxi.ServerOptions{Port: port})
  
  // Attach the auth middleware 
  vs.Use(auth.User("foo", "pas$w0rd"))
  
  // Target server to forward
  vs.Forward("http://httpbin.org")

  fmt.Printf("Server listening on port: %d\n", port)
  err := vs.Listen()
  if err != nil {
    fmt.Errorf("Error: %s\n", err)
  }
}

Custom config allowing multiple credentials types

package main

import (
  "fmt"
  "gopkg.in/vinxi/auth.v0"
  "gopkg.in/vinxi/vinxi.v0"
)

const port = 3100

func main() {
  // Create a new vinxi proxy
  vs := vinxi.NewServer(vinxi.ServerOptions{Port: port})

  // Bind the auth middleware with custom config
  // Any of the following credentials will be authorized
  tokens := []auth.Token{
    {Type: "Basic", Value: "foo:s3cr3t"},
    {Type: "Bearer", Value: "s3cr3t"},
    {Value: "s3cr3t token"},
  }
  vs.Use(auth.New(&auth.Config{Tokens: tokens}))

  // Target server to forward
  vs.Forward("http://httpbin.org")

  fmt.Printf("Server listening on port: %d\n", port)
  err := vs.Listen()
  if err != nil {
    fmt.Errorf("Error: %s\n", err)
  }
}

License

MIT