oryproxy

package module
v0.0.0-...-bf5e87f Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

Ory Proxy

A simple library that exposes a go http.Handler to proxy requests to and from an Ory Network project. The library includes sane defaults and provides an easy way to configure the proxy to fit your project needs.

The Ory CLI already provides proxy/tunnel capabilities, however, when deploying a Go service to serverless infrastructure you need to add a custom domain to your Ory Network.

This doesn't always work, since you might have test services or staging services that do not need a custom domain setup. This library helps with that.

Get Started

go get -u github.com/Benehiko/oryproxy

Setup the proxy as a standalone service

package main

import "github.com/Benehiko/oryproxy"

func main() {
    config := oryproxy.NewDefaultConfig("https://project-slug.projects.oryapis.com")
    proxy := oryproxy.NewOryProxy(config)
    proxy.ListenAndServe(ctx, 3000)
}

Or integrate into your existing service

package main

import (
    "github.com/Benehiko/oryproxy"
    "github.com/gorilla/mux"
)

func main() {
    config := oryproxy.NewDefaultConfig("https://project-slug.projects.oryapis.com")
    proxy := oryproxy.NewOryProxy(config)

    router := mux.NewRouter()
    // /.ory is the default path prefix for the proxy.
    // this can be changed.
    router.PathPrefix("/.ory").Handler(proxy.OryProxy())
}

Limitations

Although this library proxies requests to and from Ory, it is still subject to rate-limiting on the Ory Network project subscription you have. Free-tier projects can easily hit rate-limits and you should consider upgrading as soon as you have real traffic on your service.

Notice

This library is not officially supported by Ory. Please do not open support tickets on the Ory repositories regarding this project nor ask for support on their Slack channel.

Documentation

Index

Constants

View Source
const (
	OriginalHostKey middlewareContextKey = "original-host"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultConfigOptions

type DefaultConfigOptions func(*oryConfigDefault)

func WithCookieDomain

func WithCookieDomain(domain string) DefaultConfigOptions

Set the domain under which the proxy will set the cookie

func WithCorsEnabled

func WithCorsEnabled(enabled bool) DefaultConfigOptions

Enable CORS use WithCorsOptions to configure CORS Only necessary if the request to the proxy is from a browser application running on a different origin than the proxy

func WithCorsOptions

func WithCorsOptions(corsOptions *cors.Options) DefaultConfigOptions

Configure CORS

func WithOryProjectAPIKey

func WithOryProjectAPIKey(apiKey string) DefaultConfigOptions

Sets the project API key that the proxy will use with social sign in requests this value can be omitted if using password or code login/registration flows.

func WithPathPrefix

func WithPathPrefix(prefix string) DefaultConfigOptions

Set a custom value for the proxy path prefix this is the path you are serving the proxy under e.g. /.ory/proxy

func WithRequestLogger

func WithRequestLogger(logger RequestLogger) DefaultConfigOptions

A function that is called when a request is proxied this is optional

func WithResponseLogger

func WithResponseLogger(logger ResponseLogger) DefaultConfigOptions

a function that is called when a response is proxied this is optional

type OryConfig

type OryConfig interface {
	// RequestLogger is a function that is called when a request is proxied
	// to the upstream URL
	RequestLogger(context.Context) RequestLogger

	// ResponseLogger is a function that is called when a response is proxied
	// from the upstream URL
	ResponseLogger(context.Context) ResponseLogger

	// This is the cookie domain that the proxy will set on the response
	// so your project domain. This can be on localhost or something like
	// example.com
	CookieDomain(context.Context) string

	// ProxyRoutePathPrefix is the prefix under which the proxy is served.
	// for example, the proxy could be under /.ory/proxy, in which case the path prefix is /.ory/proxy
	ProxyRoutePathPrefix(context.Context) string

	// OryProjectURL is the URL of the Ory Project API
	// This is the URL that the proxy will forward requests to
	// the format is usually something like https://project-slug.projects.oryapis.com
	OryProjectURL(context.Context) string

	// OryProjectAPIKey is the API key that the proxy will use to authenticate with
	// the Ory Project API
	OryProjectAPIKey(context.Context) string

	// CorsEnabled is a flag to enable or disable CORS
	CorsEnabled(context.Context) bool

	// CorsOptions allows to configure CORS
	CorsOptions(context.Context) *cors.Options

	// TrustXForwardedHeaders is a flag that indicates whether the proxy should trust the
	// X-Forwarded-* headers or not.
	TrustXForwardedHeaders(context.Context) bool
}

func NewDefaultConfig

func NewDefaultConfig(oryProjectURL string, opts ...DefaultConfigOptions) OryConfig

type OryProxy

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

func NewOryProxy

func NewOryProxy(conf OryConfig) *OryProxy

func (*OryProxy) ListenAndServe

func (p *OryProxy) ListenAndServe(ctx context.Context, port int) error

func (*OryProxy) OryProxy

func (p *OryProxy) OryProxy() http.Handler

type RequestLogger

type RequestLogger func(ctx context.Context, req *httputil.ProxyRequest, body []byte)

type ResponseLogger

type ResponseLogger func(ctx context.Context, resp *http.Response, body []byte)

Jump to

Keyboard shortcuts

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