Skip to content
/ auth Public

HTTP authentication middleware supporting multiple schemes

License

Notifications You must be signed in to change notification settings

vinxi/auth

Repository files navigation

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

About

HTTP authentication middleware supporting multiple schemes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages