disguard

package module
v0.0.0-...-08667a2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2018 License: MIT Imports: 14 Imported by: 0

README

DisGuard - Discord OAuth Proxy GoDoc Build Status Go Report Card License

Why?

Because we want content locked to discord guild memberships.

How?

You make a file named config.yaml with contents similar to what you can find in config.example.yaml in this repository. Once done, launch the application and go to the website, if you configured it to require session, you will be sent to oauth login right away, if not, you will have to manually visit /oauth/login to get redirected. Once logged in, each request the user makes will be proxied to your defined backend, with attached named header, in example thats XWhitelistedGuilds. From there on its your job to handle that.

Session is valid for one week.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ListenAddress string `yaml:"listen_address"`
	ProxyAddress  string `yaml:"proxy_address"`

	HeaderName        string   `yaml:"header_name"`
	WhitelistedGuilds []string `yaml:"whitelisted_guilds"`
	RequireSession    bool     `yaml:"require_session"`
	IgnoredPaths      []string `yaml:"ignored_paths"`
	AuthRoot          string   `yaml:"auth_root"`

	OAuth   OAuthSection   `yaml:"oauth"`
	Session SessionSection `yaml:"session"`
}

Config ...

type Guild

type Guild struct {
	ID string `json:"id"`
}

Guild mini-container, we only care about ID.

type OAuthSection

type OAuthSection struct {
	RedirectURL  string `yaml:"redirect_url"`
	ClientID     string `yaml:"client_id"`
	ClientSecret string `yaml:"client_secret"`
	// contains filtered or unexported fields
}

OAuthSection ...

func (*OAuthSection) GetAuthorizationURL

func (conf *OAuthSection) GetAuthorizationURL() string

GetAuthorizationURL returns blah

func (*OAuthSection) GetTokenURL

func (conf *OAuthSection) GetTokenURL(code string) string

GetTokenURL returns blah

type Session

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

Session contains everything OAuth

func NewSessionRouter

func NewSessionRouter(c *Config) *Session

NewSessionRouter returns handler for session stuff

func (*Session) GetGuilds

func (o *Session) GetGuilds(tokenResponse *TokenResponse) ([]Guild, error)

GetGuilds ...

func (*Session) GetUser

func (o *Session) GetUser(tokenResponse *TokenResponse) (*User, error)

GetUser ...

func (*Session) HandleCallback

func (o *Session) HandleCallback(w http.ResponseWriter, r *http.Request)

HandleCallback ...

func (*Session) HandleLogin

func (o *Session) HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin ...

func (*Session) HandleLogout

func (o *Session) HandleLogout(w http.ResponseWriter, r *http.Request)

HandleLogout ...

func (*Session) ObtainToken

func (o *Session) ObtainToken(code string) (*TokenResponse, error)

ObtainToken ...

func (*Session) ReverseHandler

func (o *Session) ReverseHandler() *WrappedReverseProxy

ReverseHandler ...

func (*Session) Route

func (o *Session) Route(r chi.Router)

Route ...

type SessionSection

type SessionSection struct {
	HashKey  string `yaml:"hash_key"`
	BlockKey string `yaml:"block_key"`
}

SessionSection ...

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	Scope        string `json:"scope"`
}

TokenResponse contains response from OAuth

type User

type User struct {
	Avatar        string   `json:"avatar"`
	Discriminator string   `json:"discriminator"`
	ID            string   `json:"id"`
	Name          string   `json:"username"`
	Whitelisted   []string `json:"whitelisted"`
}

User struct

type WrappedReverseProxy

type WrappedReverseProxy struct {
	*httputil.ReverseProxy
	// contains filtered or unexported fields
}

WrappedReverseProxy wraps httputil reverse proxy handler to provide RequireSession Support so it would redirect to login.

func (*WrappedReverseProxy) ServeHTTP

func (w *WrappedReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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