securedservice

package
v0.0.0-...-5107ef3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const ServiceName = "secured_service"

ServiceName is the name of the service as defined in the design. This is the same value that is set in the endpoint request contexts under the ServiceKey key.

Variables

View Source
var MethodNames = [2]string{"signin", "secure"}

MethodNames lists the service method names as defined in the design. These are the same values that are set in the endpoint request contexts under the MethodKey key.

Functions

func NewSecureEndpoint

func NewSecureEndpoint(s Service, authJWTFn security.AuthJWTFunc) goa.Endpoint

NewSecureEndpoint returns an endpoint function that calls the method "secure" of service "secured_service".

func NewSigninEndpoint

func NewSigninEndpoint(s Service, authBasicFn security.AuthBasicFunc) goa.Endpoint

NewSigninEndpoint returns an endpoint function that calls the method "signin" of service "secured_service".

Types

type Auther

type Auther interface {
	// BasicAuth implements the authorization logic for the Basic security scheme.
	BasicAuth(ctx context.Context, user, pass string, schema *security.BasicScheme) (context.Context, error)
	// JWTAuth implements the authorization logic for the JWT security scheme.
	JWTAuth(ctx context.Context, token string, schema *security.JWTScheme) (context.Context, error)
}

Auther defines the authorization functions to be implemented by the service.

type Client

type Client struct {
	SigninEndpoint goa.Endpoint
	SecureEndpoint goa.Endpoint
}

Client is the "secured_service" service client.

func NewClient

func NewClient(signin, secure goa.Endpoint) *Client

NewClient initializes a "secured_service" service client given the endpoints.

func (*Client) Secure

func (c *Client) Secure(ctx context.Context, p *SecurePayload) (res string, err error)

Secure calls the "secure" endpoint of the "secured_service" service. Secure may return the following errors:

  • "invalid-scopes" (type InvalidScopes)
  • error: internal error

func (*Client) Signin

func (c *Client) Signin(ctx context.Context, p *SigninPayload) (res *Creds, err error)

Signin calls the "signin" endpoint of the "secured_service" service.

type Creds

type Creds struct {
	// JWT token
	JWT string
}

Creds is the result type of the secured_service service signin method.

type Endpoints

type Endpoints struct {
	Signin goa.Endpoint
	Secure goa.Endpoint
}

Endpoints wraps the "secured_service" service endpoints.

func NewEndpoints

func NewEndpoints(s Service) *Endpoints

NewEndpoints wraps the methods of the "secured_service" service with endpoints.

func (*Endpoints) Use

func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint)

Use applies the given middleware to all the "secured_service" service endpoints.

type InvalidScopes

type InvalidScopes string

Token scopes are invalid

func (InvalidScopes) Error

func (e InvalidScopes) Error() string

Error returns an error description.

func (InvalidScopes) ErrorName

func (e InvalidScopes) ErrorName() string

ErrorName returns "invalid-scopes".

type SecurePayload

type SecurePayload struct {
	// Are these exposed for unauthenticated requests?
	Test *string
	// JWT used for authentication
	Token string
}

SecurePayload is the payload type of the secured_service service secure method.

type Service

type Service interface {
	// Creates a valid JWT
	Signin(context.Context, *SigninPayload) (res *Creds, err error)
	// This action is secured with the jwt scheme
	Secure(context.Context, *SecurePayload) (res string, err error)
}

The secured service exposes endpoints that require valid authorization credentials.

type SigninPayload

type SigninPayload struct {
	// Username used to perform signin
	Username string
	// Password used to perform signin
	Password string
}

Credentials used to authenticate to retrieve JWT token

type Unauthorized

type Unauthorized string

Credentials are invalid

func (Unauthorized) Error

func (e Unauthorized) Error() string

Error returns an error description.

func (Unauthorized) ErrorName

func (e Unauthorized) ErrorName() string

ErrorName returns "unauthorized".

Jump to

Keyboard shortcuts

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