strapi_auth_client

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

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

Go to latest
Published: Aug 30, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

README

KrakenD strapi authentication

A http client for the KrakenD framework supporting the strapi "local" authentication method.

How to use it?

This package exposes single factory capable to create a instances of the proxy.HTTPClientFactory interface embedding a http client supporting the oauth2 client credentials workflow

import 	(
	"context"
	"net/http"
	"github.com/devopsfaith/krakend/config"
	"github.com/devopsfaith/krakend/proxy"
	"github.com/pushrbx/krakend-strapi-auth"
)

requestExecutorFactory := func(cfg *config.Backend) proxy.HTTPRequestExecutor {
	clientFactory := oauth2client.NewHTTPClient(cfg)
	return func(ctx context.Context, req *http.Request) (*http.Response, error) {
		return clientFactory(ctx).Do(req.WithContext(ctx))
	}
}

You can create your own proxy.HTTPRequestExecutor and inject it into your BackendFactory

Disclaimer

Big chunk of the code is a copy/paste from golang/oauth2 and devopsfaith/krakend-oauth2-clientcredentials.

Documentation

Index

Constants

View Source
const Namespace = "github.com/pushrbx/krakend-strapi-auth"

Variables

View Source
var ZeroCfg = Config{}

Functions

func NewClient

func NewClient(ctx context.Context, src TokenSource) *http.Client

func NewHTTPClient

func NewHTTPClient(cfg *config.Backend) client.HTTPClientFactory

Types

type Config

type Config struct {
	IsDisabled bool
	Identifier string
	Password   string
	AuthUrl    string
}

func (*Config) TokenSource

func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource

type LocalAuthConfig

type LocalAuthConfig struct {
	IsDisabled bool
	Identifier string
	Password   string
	AuthUrl    string
}

func (*LocalAuthConfig) Client

func (c *LocalAuthConfig) Client(ctx context.Context) *http.Client

func (*LocalAuthConfig) TokenSource

func (c *LocalAuthConfig) TokenSource(ctx context.Context) TokenSource

type RetrieveError

type RetrieveError struct {
	Response *http.Response
	// Body is the body that was consumed by reading Response.Body.
	// It may be truncated.
	Body []byte
}

func (*RetrieveError) Error

func (r *RetrieveError) Error() string

type Token

type Token struct {
	Jwt  string               `json:"jwt"`
	User internal.UserProfile `json:"user"`
	// contains filtered or unexported fields
}

func (*Token) SetAuthHeader

func (t *Token) SetAuthHeader(r *http.Request)

func (*Token) Valid

func (t *Token) Valid() bool

func (*Token) WithExtra

func (t *Token) WithExtra(extra interface{}) *Token

type TokenSource

type TokenSource interface {
	Token() (*Token, error)
}

func ReuseTokenSource

func ReuseTokenSource(t *Token, src TokenSource) TokenSource

type Transport

type Transport struct {
	// Source supplies the token to add to outgoing requests'
	// Authorization headers.
	Source TokenSource

	// Base is the base RoundTripper used to make HTTP requests.
	// If nil, http.DefaultTransport is used.
	Base http.RoundTripper
	// contains filtered or unexported fields
}

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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