Back to

Package mockadfs

Latest Go to latest

The highest tagged major version is .

Published: Apr 29, 2019 | License: Apache-2.0 | Module:


func AddApiEndpoints

func AddApiEndpoints(router *mux.Router, es []ApiEndpoint)

AddRoutes is a helper for APIs to register their request handlers.

func BadRequest

func BadRequest(msg string) http.Handler

func CatchPanic

func CatchPanic(h http.Handler) http.Handler

func Forbidden

func Forbidden(msg string) http.Handler

func HandleEntity

func HandleEntity(
	r *http.Request,
	unmarshal func([]byte) (interface{}, error),
	fun func(interface{}) http.Handler) http.Handler

HandleEntity expects a entity in the request body. It needs an `empty` function to create a structure to deserialize into.

func NewMockADFSServer

func NewMockADFSServer(oauthService *OAuthService) *mux.Router

NewMockADFSServer creates a new auth server for ADFS

func Ok

func Ok(data interface{}) http.Handler

func RequestHandler

func RequestHandler(fun RequestHandlerFunc) http.Handler

RequestHandler wraps handlers so that they only access the request.

type AdfsClaims

type AdfsClaims struct {
	Email      string      `json:"email"`
	Upn        string      `json:"upn"`
	Role       interface{} `json:"role"`
	AuthTime   string      `json:"auth_time"`
	AuthMethod string      `json:"authmethod"`
	Ver        string      `json:"ver"`
	AppId      string      `json:"appid"`

Access token / claims with JSON mappings. The difference between this and the one in `testutils` is that this one will serialize one role as a string, not as an array.

type ApiEndpoint

type ApiEndpoint = struct {
	// contains filtered or unexported fields

type Controller

type Controller interface {
	AddRoutes(router *mux.Router)

Controller is the interface for the HTTP Router

type JsonHandler

type JsonHandler struct {
	Status int
	Data   interface{}

func (JsonHandler) ServeHTTP

func (h JsonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LoginView

type LoginView struct {
	// contains filtered or unexported fields

func NewLoginView

func NewLoginView(service *OAuthService) *LoginView

func (*LoginView) AddRoutes

func (view *LoginView) AddRoutes(r *mux.Router)

func (*LoginView) Get

func (view *LoginView) Get(w http.ResponseWriter, r *http.Request)

func (*LoginView) Post

func (view *LoginView) Post(w http.ResponseWriter, r *http.Request)

type Msg

type Msg struct {
	Message string `json:"message"`

type OAuthApi

type OAuthApi struct {
	// contains filtered or unexported fields

func (*OAuthApi) AddRoutes

func (api *OAuthApi) AddRoutes(r *mux.Router)

func (*OAuthApi) Authorise

func (api *OAuthApi) Authorise(r *http.Request) http.Handler

func (*OAuthApi) Token

func (api *OAuthApi) Token(r *http.Request) http.Handler

Token retrieves a JWT token in exchange for a pre-authorized code or a refresh token.

type OAuthService

type OAuthService struct {
	// contains filtered or unexported fields

func NewOAuthService

func NewOAuthService(

	clientId, redirectUri, resource string,
	repo *UserRepo, tokenLifetime time.Duration) *OAuthService

func (*OAuthService) AuthoriseUser

func (svc *OAuthService) AuthoriseUser(url *url.URL, user User) (string, error)

AuthoriseUser returns a code or an error.

func (*OAuthService) CallbackUrl

func (svc *OAuthService) CallbackUrl(u *url.URL, code string) *url.URL

func (*OAuthService) Claims

func (svc *OAuthService) Claims(user User) AdfsClaims

func (*OAuthService) Redeem

func (svc *OAuthService) Redeem(code string) (User, string, bool)

Redeem tries to retrieve the user that AuthorisationCode stored. It will also remove the code so it can only be redeemed once, but return a refresh token that can be used to keep the user logged in.

func (*OAuthService) Refresh

func (svc *OAuthService) Refresh(token string) (User, error)

func (*OAuthService) Sign

func (svc *OAuthService) Sign(claims AdfsClaims) string

Sign turns claims into a token.

func (*OAuthService) UserCode

func (svc *OAuthService) UserCode(user User) string

UserCode generates a code for a user that can be later used to get a token for this user.

type RequestHandlerFunc

type RequestHandlerFunc = func(r *http.Request) http.Handler

RequestHandlerFunc restricts access to the request only.

type User

type User struct {
	Username string   `json:"username"`
	Email    string   `json:"email"`
	Roles    []string `json:"roles"`

User is a user definition either from config or via REST

type UserApi

type UserApi struct {
	// contains filtered or unexported fields

func (*UserApi) AddRoutes

func (api *UserApi) AddRoutes(r *mux.Router)

func (*UserApi) DeleteDefaultUser

func (api *UserApi) DeleteDefaultUser(r *http.Request) http.Handler

func (*UserApi) DeleteUsers

func (api *UserApi) DeleteUsers(r *http.Request) http.Handler

func (*UserApi) GetDefaultUser

func (api *UserApi) GetDefaultUser(r *http.Request) http.Handler

func (*UserApi) GetUsers

func (api *UserApi) GetUsers(r *http.Request) http.Handler

func (*UserApi) PostDefaultUser

func (api *UserApi) PostDefaultUser(r *http.Request) http.Handler

func (*UserApi) PostUser

func (api *UserApi) PostUser(r *http.Request) http.Handler

type UserRepo

type UserRepo struct {
	// contains filtered or unexported fields

func NewUserRepo

func NewUserRepo() *UserRepo

func (*UserRepo) Add

func (repo *UserRepo) Add(user User)

func (*UserRepo) Default

func (repo *UserRepo) Default() *User

func (*UserRepo) Delete

func (repo *UserRepo) Delete(pred func(*User) bool) int

func (*UserRepo) Find

func (repo *UserRepo) Find(pred func(*User) bool) []User

func (*UserRepo) GetByUsername

func (repo *UserRepo) GetByUsername(username string) (User, bool)

func (*UserRepo) SetDefault

func (repo *UserRepo) SetDefault(user *User)

type Username

type Username = string

Package Files

  • api.go
  • login.go
  • main.go
  • oauthapi.go
  • repo.go
  • userapi.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier