middlewares

package
v0.0.0-...-8717a1f Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Authentication = func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
			claims := map[string]interface{}{
				"userid":   float64(1),
				"fullname": "unknown",
				"email":    "test",
				"scope":    "test",
			}

			req = req.WithContext(context.WithValue(req.Context(), contextkey.AccessToken, claims))
			req = req.WithContext(context.WithValue(req.Context(), contextkey.AccessTokenKey, "test"))
			next.ServeHTTP(res, req)
		})
	}

	AuthenticationWithCustomClaims = func(customClaims map[string]interface{}) func(next http.Handler) http.Handler {
		return func(next http.Handler) http.Handler {
			return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
				claims := map[string]interface{}{
					"userid":   float64(1),
					"fullname": "unknown",
					"email":    "test",
				}

				for key, val := range customClaims {
					claims[key] = val
				}

				req = req.WithContext(context.WithValue(req.Context(), contextkey.AccessToken, claims))
				req = req.WithContext(context.WithValue(req.Context(), contextkey.AccessTokenKey, "test"))
				next.ServeHTTP(res, req)
			})
		}
	}
)
View Source
var (
	Bypass = func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
			next.ServeHTTP(res, req)
		})
	}

	BypassWithArgs = func(next http.Handler, args ...interface{}) http.Handler {
		return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
			next.ServeHTTP(res, req)
		})
	}
)
View Source
var (
	ClientParser = func(next http.Handler, args ...interface{}) http.Handler {
		return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
			clientInfoMap := map[string]interface{}{
				"client_id":   -1,
				"client_name": "unknown",
				"ip":          "test",
				"user_agent":  "test",
			}

			req = req.WithContext(context.WithValue(req.Context(), contextkey.ClientInfo, map[string]interface{}(clientInfoMap)))
			next.ServeHTTP(res, req)
		})
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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