oauth

package
v0.0.0-...-d4aa6c0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2016 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

This middleware package for OAauth is incomplete (although it's working). It needs tests and some more documentation. Any help is welcome...

Index

Constants

View Source
const (
	AttrUser = "oauth_user"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ClientID is the application's ID.
	ClientID string `yaml:"client_id"`
	// ClientSecret is the application's secret.
	ClientSecret string `yaml:"client_secret"`

	// The provider's authentication url
	AuthURL string `yaml:"auth_url"`
	// The providers token fetching url
	TokenURL string `yaml:"token_url"`

	// RedirectURL is the URL to redirect users going through
	// the OAuth flow, after the resource owner's URLs.
	RedirectURL string `yaml:"redirect_url"`

	// Scope specifies optional requested permissions.
	Scopes []string `yaml:"scopes"`
}

OAuth2 config. This is copied from the oauth2 library so it can be parsed from yaml with added tags

type JWTAuthenticator

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

JWTAuthenticator authenticates users from JWT encoded cookies

func NewJWTAuthenticator

func NewJWTAuthenticator(key string) *JWTAuthenticator

func (*JWTAuthenticator) DecodeToken

func (j *JWTAuthenticator) DecodeToken(data string) (interface{}, error)

func (*JWTAuthenticator) EncodeToken

func (j *JWTAuthenticator) EncodeToken(data interface{}) (string, error)

func (*JWTAuthenticator) Login

func (j *JWTAuthenticator) Login(token *oauth2.Token) (interface{}, error)

Login just returns the access token. In a real-world situation here's where you'd want to talk to your database

type OAuthMiddleware

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

OAuthMiddleware is a middleware that can protect routes and make sure the user is logged in. It uses JWT to encode cookies with the user token

func NewOAuthMiddleware

func NewOAuthMiddleware(config *Config, validator UserValidator) *OAuthMiddleware

NewOAuthMiddleware crea

func (*OAuthMiddleware) Handle

func (o *OAuthMiddleware) Handle(w http.ResponseWriter, r *vertex.Request, next vertex.HandlerFunc) (interface{}, error)

func (*OAuthMiddleware) LoginHandler

func (o *OAuthMiddleware) LoginHandler() vertex.Route

type TokenProtocol

type TokenProtocol interface {
	EncodeToken(interface{}) (string, error)
	DecodeToken(string) (interface{}, error)
}

TokenProtocol is an interface for encoding/decoding user tokens. Currently we're using a JWT token encoder/decoder

type UserValidator

type UserValidator interface {
	TokenProtocol
	Login(token *oauth2.Token) (interface{}, error)
}

UserValidator takes care of logging in users with tokens. Currently uses JWT encoding of the user id, without any DB behind this

Jump to

Keyboard shortcuts

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