auth

package module
v0.0.0-...-826d3bf Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2015 License: MIT Imports: 14 Imported by: 0

README

proxy-auth

This is a small module which provides a small authentication interface you can embed into proxy servers. It currently supports authentication to GitHub using Oauth2.

usage

Download this package.

go get github.com/wolfeidau/proxy-auth

An example server is shown below.

package main

import (
    "net/http"

    "github.com/gorilla/mux"
    "github.com/gorilla/sessions"
    "github.com/wolfeidau/proxy-auth"
)

func main() {

    // configure the github oauth parameters
    config := &auth.GitHubConfig{
        &auth.Config{
            ClientID:     os.Getenv("GITHUB_CLIENT_ID"),
            ClientSecret: os.Getenv("GITHUB_CLIENT_SECRET"),
            CallbackURL:  os.Getenv("GITHUB_CALLBACK_URL"),
        },
    }
    auth.SetGitHubConfig(config)

    // setup a store, in our case one using secure cookies
    store := sessions.NewCookieStore([]byte("something-very-secret"))
    s := auth.NewServer(store)

    // configure a mux
    r := mux.NewRouter()
    r.PathPrefix(auth.PathPrefix).Handler(s.GetMux())

    // add a wrapper to check the session for each request
    o := auth.CheckSession(r, store)

    // listen to the network
    http.ListenAndServe(":5000", o)
}

License

This code is Copyright (c) 2014 Mark Wolfe and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.txt file for more details.

Documentation

Index

Constants

View Source
const (
	// PathPrefix the path used by this authentication module
	PathPrefix = "/auth"
	// LoginURL is the URL which users are redirected to if they aren't logged in
	LoginURL = "/auth/login"
)

Variables

This section is empty.

Functions

func CheckSession

func CheckSession(handler http.Handler, store sessions.Store) http.Handler

CheckSession middleware function to validate the session cookie is set

func SetGitHubConfig

func SetGitHubConfig(c *GitHubConfig)

SetGitHubConfig Override the GitHub oauth configuration

Types

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	CallbackURL  string
}

Config base authentication configuration

type GitHubConfig

type GitHubConfig struct {
	*Config
}

GitHubConfig github auth configuration

type GitHubUser

type GitHubUser struct {
	Name      string `json:"name"`
	Email     string `json:"email"`
	AvatarURL string `json:"avatar_url"`
}

GitHubUser represents a user in the github API

func DecodeGitHubUser

func DecodeGitHubUser(buf []byte) (*GitHubUser, error)

DecodeGitHubUser decode json into a user object

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server the authentication server

func NewServer

func NewServer(sessionStore sessions.Store) *Server

NewServer creates a server with the standard endpionts registered

func (*Server) GetMux

func (s *Server) GetMux() *mux.Router

GetMux returns the mux with the standard http handlers already registered

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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