authservice

package module
v0.0.0-...-8b2e2b7 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: LGPL-3.0 Imports: 7 Imported by: 0

README

gateway-auth-service

Go Reference

Authorization service for DevopsHaven API Gateway

This snippet shows how can you implement your authorization logic for your services.

The service communicates with the gateway via insecure gRPC protocol.

package main

import authservice "github.com/devopshaven/gateway-auth-service"

...

// Auth request handler function
func handleAuthRequest(req *authservice.AuthRequest) error {
	// Allow request with additional headers.
	headers := make(http.Header)

	// These two headers will also passed to the upstream server.
	headers.Set("X-Auth-User-Id", uuid.NewString())
	headers.Set("X-Laos", "panda")

    // Allow request
	req.Passtrough(headers)

    // or Block request example with message
	req.BlockWithError(500, "Request blocked")

	return nil
}

func main() {
    ...

	// Creating new instance from the auth service and listen on port 5009
	authservice.NewGatewayAuthService(ctx, ":5009", handleAuthRequest)

	...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGatewayAuthService

func NewGatewayAuthService(ctx context.Context, listen string, handler AuthHandler)

NewGatewayAuthService initializes a new instance from the auth service. The third parameter is the callback function for authentication requests. There you can block or allow pass-trough requests with additional header manipulation.

Types

type AuthHandler

type AuthHandler func(*AuthRequest) error

type AuthRequest

type AuthRequest struct {
	ContentType string
	Method      string
	Host        string
	URL         string
	Header      http.Header
	// contains filtered or unexported fields
}

AuthRequest authorization request from the Gateway service. You can block or allow pass-trough with Passtrough and BlockWithContent or BlockWithError methods.

func (*AuthRequest) BlockWithContent

func (ar *AuthRequest) BlockWithContent(status int, contentType string, content []byte)

BlockWithError blocks the request with specific content.

func (*AuthRequest) BlockWithError

func (ar *AuthRequest) BlockWithError(status int, message string)

BlockWithError block the request with plain text error.

func (*AuthRequest) Passtrough

func (ar *AuthRequest) Passtrough(additionalHeaders http.Header)

Passtrough allow the gateway to send the data to the upstream.

type AuthResult

type AuthResult struct {
	// Block indicates wether the request should be blocked or not.
	Block bool
	// contains filtered or unexported fields
}

func (AuthResult) AddHeaders

func (ar AuthResult) AddHeaders(h http.Header)

AddHeaders sets additional headers which sent by the auth server.

func (AuthResult) RenderError

func (ar AuthResult) RenderError(wr http.ResponseWriter) error

func (AuthResult) String

func (ar AuthResult) String() string

type AuthService

type AuthService struct {
}

type Client

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

func NewClient

func NewClient(endpoint string) *Client

func (*Client) Authorize

func (c *Client) Authorize(ctx context.Context, method, host, url string, headers http.Header) (*AuthResult, error)

func (*Client) Close

func (c *Client) Close() error

Directories

Path Synopsis
internal
pb

Jump to

Keyboard shortcuts

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