apigateway

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: Unlicense Imports: 11 Imported by: 0

README

@baturalpk/api-gateway ⛩️

✈ Getting started

go get github.com/baturalpk/apigateway

See examples/ folder for sample config.yaml and main.go files.

🔥 Works well with @baturalpk/auth-service as intended to be.

⚙ How does it work?

  1. Each request that matches with /auth/:intent schema, is forwarded to the auth service endpoints depending on the intents (i.e., signin, signout, signup).

  2. Each request that begins with /api/..., is evaluated to match with predefined paths (matchPaths[].value property in config.yaml):

    • If matching occurs, the gateway determines whether end-user is authorized by interacting with the auth service endpoint

    • If claimed authorization is valid:

      • Binds the unique identifier (i.e., ID) of verified user to the predefined header (auth.internal.idHeader property in config.yaml). By that way, internal services can trust this header to recognize the authenticated end-user.
      • Ultimately, the request of end-user is forwarded to the target service by reverse proxy.

😒 Some limitations

  • All auth service paths (e.g., signupPath) must allow HTTP POST method

  • After the successful validation of an end-user session, auth service must return a JSON response with the following property:

    id: "System-wide strictly unique identifier" of an end-user.

  • All requests, which are going towards internal services, must be fully authorized. For the time being, different paths that belong to same service cannot be excluded from authorization process conditionally. In brief, no public API endpoints yet!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewReverseProxy

func NewReverseProxy(conf Config) *reverseProxy

func PrepareConfigFile

func PrepareConfigFile(name string, searchPaths []string)

Types

type Auth added in v0.2.0

type Auth struct {
	Internal       AuthInternal
	BasePath       string
	SigninPath     string
	SignoutPath    string
	SignupPath     string
	ValidationPath string
}

type AuthInternal added in v0.2.0

type AuthInternal struct {
	IDHeader string
}

type Config

type Config struct {
	Auth       Auth
	Gateway    Gateway
	MatchPaths []MatchPaths
}

func NewConfig

func NewConfig() (Config, error)

type Gateway

type Gateway struct {
	Schema      string
	TLSCertFile string
	TLSKeyFile  string
	Port        uint16
}

type MatchPaths

type MatchPaths struct {
	Value      string
	TargetHost string
	TargetPort uint16
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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