adapter

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2017 License: MIT Imports: 26 Imported by: 0

README

Circle CI

go-nginx-oauth2-adapter

a golang port for sorah/nginx_omniauth_adapter

PREREQUISITE

  • nginx with ngx_http_auth_request_module, or h2o with mruby

USAGE

$ go get github.com/shogo82148/go-nginx-oauth2-adapter/cli/go-nginx-oauth2-adapter
$ go-nginx-oauth2-adapter

CONFIGURATION

The example of configuration file.

address: ":18081" # listen address

# secret tokens to authenticate/encrypt cookie.
# see http://www.gorillatoolkit.org/pkg/sessions for more detail.
# use `-genkey` option to create strong keys.
secrets:
  - new-authentication-key
  - new-encryption-key
  - old-authentication-key
  - old-encryption-key
session_name: go-nginx-oauth2-session
app_refresh_interval: 24h

# cookie settings for saving session
cookie:
  path: /
  domain:
  max_age: 0
  secure: true # default: false. It is recommended to set true.
  http_only: true # default: false. It is recommended to set true.

providers:
  # development: {} # For test.
  google_oauth2:
    client_id: YOUR_CLIENT_ID
    client_secret: YOUR_CLIENT_SECRET
    scopes: "openid,email,profile" # default: "openid,email,profile"
    restrictions:
      - example.com # domain of your Google App
      - specific.user@example.com

LICENSE

This software is released under the MIT License, see LICENSE.md.

SEE ALSO

Documentation

Index

Constants

View Source
const Version = "0.3.0"

Version is the version of go-nginx-oauth2-adapter.

Variables

View Source
var ErrForbidden = errors.New("shogo82148/go-nginx-oauth2-adapter/provider: access forbidden")

ErrForbidden is the error which the access is forbidden.

View Source
var ErrProviderConfigNotFound = errors.New("shogo82148/go-nginx-oauth2-adapter: provider configure not found")

ErrProviderConfigNotFound is the error which provider configure is not found.

Functions

func LoggingHandler

func LoggingHandler(h http.Handler) http.Handler

LoggingHandler logs HTTP requests.

func Main

func Main(args []string) int

Main starts the go-nginx-oauth2-adapter server.

func RegisterProvider

func RegisterProvider(name string, provider Provider)

RegisterProvider registers the OAuth provider.

Types

type Config

type Config struct {
	Address            string                            `yaml:"address" json:"address"`
	Secrets            []*string                         `yaml:"secrets" json:"secrets"`
	SessionName        string                            `yaml:"session_name" json:"session_name"`
	Providers          map[string]map[string]interface{} `yaml:"providers" json:"providers"`
	AppRefreshInterval string                            `yaml:"app_refresh_interval" json:"app_refresh_interval"`

	// set with -configtest option.
	ConfigTest bool `yaml:"-" json:"-"`

	// Fields are a subset of http.Cookie fields.
	Cookie *CookieConfig `yaml:"cookie" json:"cookie"`
}

Config is a configration for go-nginx-oauth2-adapter.

func NewConfig

func NewConfig() *Config

NewConfig returns a new config.

func (*Config) LoadEnv

func (c *Config) LoadEnv() error

LoadEnv loads the config from the environment values.

func (*Config) LoadYaml

func (c *Config) LoadYaml(filename string) error

LoadYaml loads the config from yaml file.

type CookieConfig

type CookieConfig struct {
	Path   string `yaml:"path" json:"path"`
	Domain string `yaml:"domain" json:"domain"`
	// MaxAge=0 means no 'Max-Age' attribute specified.
	// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'.
	// MaxAge>0 means Max-Age attribute present and given in seconds.
	MaxAge   int  `yaml:"max_age" json:"max_age"`
	Secure   bool `yaml:"secure" json:"secure"`
	HTTPOnly bool `yaml:"http_only" json:"http_only"`
}

CookieConfig is a configration for the cookie of HTTP.

func (*CookieConfig) Options

func (c *CookieConfig) Options() *sessions.Options

Options returns the sesseion config.

type Provider

type Provider interface {
	ParseConfig(configFile map[string]interface{}) (ProviderConfig, error)
}

Provider is an OAuth provider.

type ProviderConfig

type ProviderConfig interface {
	Config() oauth2.Config
	Info(c *oauth2.Config, t *oauth2.Token) (string, map[string]interface{}, error)
}

ProviderConfig is a config for an OAuth provider.

type ProviderInfoContext added in v0.3.0

type ProviderInfoContext interface {
	InfoContext(ctx context.Context, c *oauth2.Config, t *oauth2.Token) (string, map[string]interface{}, error)
}

ProviderInfoContext is for support context.Context.

type Server

type Server struct {
	Config             Config
	DefaultPrivider    string
	ProviderConfigs    map[string]ProviderConfig
	SessionStore       sessions.Store
	AppRefreshInterval time.Duration
}

Server is the go-nginx-oauth2-adapter server.

func NewServer

func NewServer(config Config) (*Server, error)

NewServer returns a new go-nginx-oauth2-adapter server.

func (*Server) HandlerCallback

func (s *Server) HandlerCallback(w http.ResponseWriter, r *http.Request)

HandlerCallback validates the user infomation, set to cookie

func (*Server) HandlerInitiate

func (s *Server) HandlerInitiate(w http.ResponseWriter, r *http.Request)

HandlerInitiate redirects to authorization page.

func (*Server) HandlerTest

func (s *Server) HandlerTest(w http.ResponseWriter, r *http.Request)

HandlerTest validates the session.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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