client

package
v7.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const AppJOSE coap.MediaType = 11650

CoAP Content-Formats registry does not contain a JOSE value, using an unassigned value

Variables

View Source
var (
	// Success response codes
	// https://tools.ietf.org/html/rfc7252#section-5.9.1
	CodeCreated = ResponseCode{
		HTTP:    http.StatusCreated,
		CoAP:    codes.Created,
		Name:    "created",
		Success: true,
	}
	CodeDeleted = ResponseCode{
		HTTP:    http.StatusNoContent,
		CoAP:    codes.Deleted,
		Name:    "deleted",
		Success: true,
	}
	CodeValid = ResponseCode{
		HTTP:    http.StatusNotModified,
		CoAP:    codes.Valid,
		Name:    "valid",
		Success: true,
	}
	CodeChanged = ResponseCode{
		HTTP:    http.StatusNoContent,
		CoAP:    codes.Changed,
		Name:    "changed",
		Success: true,
	}
	CodeContent = ResponseCode{
		HTTP:    http.StatusOK,
		CoAP:    codes.Content,
		Name:    "content",
		Success: true,
	}
	// Client error codes
	// https://tools.ietf.org/html/rfc7252#section-5.9.2
	CodeBadRequest = ResponseCode{
		HTTP:    http.StatusBadRequest,
		CoAP:    codes.BadRequest,
		Name:    "bad request",
		Success: false,
	}
	CodeUnauthorized = ResponseCode{
		HTTP:    http.StatusUnauthorized,
		CoAP:    codes.Unauthorized,
		Name:    "unauthorized",
		Success: false,
	}
	CodeBadOption = ResponseCode{
		HTTP:    0,
		CoAP:    codes.BadOption,
		Name:    "bad option",
		Success: false,
	}
	CodeForbidden = ResponseCode{
		HTTP:    http.StatusForbidden,
		CoAP:    codes.Forbidden,
		Name:    "forbidden",
		Success: false,
	}
	CodeNotFound = ResponseCode{
		HTTP:    http.StatusNotFound,
		CoAP:    codes.NotFound,
		Name:    "not found",
		Success: false,
	}
	CodeMethodNotAllowed = ResponseCode{
		HTTP:    http.StatusMethodNotAllowed,
		CoAP:    codes.MethodNotAllowed,
		Name:    "method not allowed",
		Success: false,
	}
	CodeNotAcceptable = ResponseCode{
		HTTP:    http.StatusNotAcceptable,
		CoAP:    codes.NotAcceptable,
		Name:    "not acceptable",
		Success: false,
	}
	CodePreconditionFailed = ResponseCode{
		HTTP:    http.StatusPreconditionFailed,
		CoAP:    codes.PreconditionFailed,
		Name:    "precondition failed",
		Success: false,
	}
	CodeRequestEntityTooLarge = ResponseCode{
		HTTP:    http.StatusRequestEntityTooLarge,
		CoAP:    codes.RequestEntityTooLarge,
		Name:    "request entity too large",
		Success: false,
	}
	CodeUnsupportedContentFormat = ResponseCode{
		HTTP:    http.StatusUnsupportedMediaType,
		CoAP:    codes.UnsupportedMediaType,
		Name:    "unsupported content format",
		Success: false,
	}
	// Server error codes
	// https://tools.ietf.org/html/rfc7252#section-5.9.3
	CodeInternalServerError = ResponseCode{
		HTTP:    http.StatusInternalServerError,
		CoAP:    codes.InternalServerError,
		Name:    "internal server error",
		Success: false,
	}
	CodeNotImplemented = ResponseCode{
		HTTP:    http.StatusNotImplemented,
		CoAP:    codes.NotImplemented,
		Name:    "not implemented",
		Success: false,
	}
	CodeBadGateway = ResponseCode{
		HTTP:    http.StatusBadGateway,
		CoAP:    codes.BadGateway,
		Name:    "bad gateway",
		Success: false,
	}
	CodeServiceUnavailable = ResponseCode{
		HTTP:    http.StatusServiceUnavailable,
		CoAP:    codes.ServiceUnavailable,
		Name:    "service unavailable",
		Success: false,
	}
	CodeGatewayTimeout = ResponseCode{
		HTTP:    http.StatusGatewayTimeout,
		CoAP:    codes.GatewayTimeout,
		Name:    "gateway timeout",
		Success: false,
	}
	CodeProxyingNotSupported = ResponseCode{
		HTTP:    0,
		CoAP:    codes.ProxyingNotSupported,
		Name:    "proxying not supported",
		Success: false,
	}
)

ResponseCodes list all the mapped response codes

Functions

func SetAuthenticationTree

func SetAuthenticationTree(connection Connection, tree string)

SetAuthenticationTree changes the authentication tree that the connection was created with. This is a convenience function for functional testing.

Types

type AMInfoResponse

type AMInfoResponse struct {
	Realm              string
	AccessTokenURL     string
	IntrospectURL      string
	AttributesURL      string
	ThingsVersion      string
	UserCodeURL        string
	UserTokenURL       string
	SessionsVersion    string
	SessionValidateURL string
	SessionLogoutURL   string
}

AMInfoResponse contains the information required to construct valid signed JWTs

type AuthenticatePayload

type AuthenticatePayload struct {
	SessionToken
	AuthId    string              `json:"authId,omitempty"`
	AuthIDKey string              `json:"auth_id_digest,omitempty"`
	Callbacks []callback.Callback `json:"callbacks,omitempty"`
}

AuthenticatePayload represents the outbound and inbound data during an authentication request

func (AuthenticatePayload) HasSessionToken

func (p AuthenticatePayload) HasSessionToken() bool

HasSessionToken returns true if the payload contains a session token Indicates that the authentication workflow has completed successfully

func (AuthenticatePayload) String

func (p AuthenticatePayload) String() string

type Connection

type Connection interface {
	// Initialise the client. Must be called before the Client is used by a Thing
	Initialise() error

	// Authenticate sends an authenticate request to the ForgeRock platform
	Authenticate(payload AuthenticatePayload) (reply AuthenticatePayload, err error)

	// AMInfo returns the information required to construct valid signed JWTs
	AMInfo() (info AMInfoResponse, err error)

	// ValidateSession sends a validate session request
	ValidateSession(tokenID string, content ContentType, payload string) (ok bool, err error)

	// LogoutSession makes a request to logout the session
	LogoutSession(tokenID string, content ContentType, payload string) (err error)

	// AccessToken makes an access token request with the given session token and payload
	AccessToken(tokenID string, content ContentType, payload string) (reply []byte, err error)

	// IntrospectAccessToken makes a request to introspect an access token
	IntrospectAccessToken(tokenID string, content ContentType, payload string) (introspection []byte, err error)

	// Attributes makes a thing attributes request with the given session token and payload
	Attributes(tokenID string, content ContentType, payload string, names []string) (reply []byte, err error)

	// UserCode makes a user code request with the given session token and payload
	UserCode(tokenID string, content ContentType, payload string) (reply []byte, err error)

	// UserToken makes a user token request with the given session token and payload
	UserToken(tokenID string, content ContentType, payload string) (reply []byte, err error)
}

Connection to the ForgeRock platform

type ConnectionBuilder

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

func NewConnection

func NewConnection() *ConnectionBuilder

func (*ConnectionBuilder) ConnectTo

func (b *ConnectionBuilder) ConnectTo(url *url.URL) *ConnectionBuilder

func (*ConnectionBuilder) Create

func (b *ConnectionBuilder) Create() (Connection, error)

func (*ConnectionBuilder) InRealm

func (b *ConnectionBuilder) InRealm(realm string) *ConnectionBuilder

func (*ConnectionBuilder) TimeoutRequestAfter

func (b *ConnectionBuilder) TimeoutRequestAfter(timeout time.Duration) *ConnectionBuilder

func (*ConnectionBuilder) WithKey

func (*ConnectionBuilder) WithTree

func (b *ConnectionBuilder) WithTree(tree string) *ConnectionBuilder

type ContentType

type ContentType string
const (
	ApplicationJSON ContentType = "application/json"
	ApplicationJOSE ContentType = "application/jose"
)

type GetAccessTokenPayload

type GetAccessTokenPayload struct {
	Scope        []string `json:"scope,omitempty"`
	RefreshToken string   `json:"refresh_token,omitempty"`
}

func (GetAccessTokenPayload) String

func (p GetAccessTokenPayload) String() string

type IntrospectPayload

type IntrospectPayload struct {
	Token         string `json:"token"`
	TokenTypeHint string `json:"token_type_hint,omitempty"`
}

IntrospectPayload contains an introspection request as defined by rfc7662

type ResponseCode added in v7.1.0

type ResponseCode struct {
	HTTP    int
	CoAP    codes.Code
	Name    string
	Success bool
}

ResponseCode is used to relay the outcome of HTTP/CoAP requests made to AM/Gateway

func (ResponseCode) IsWrappedIn added in v7.1.0

func (r ResponseCode) IsWrappedIn(err error) bool

IsWrappedIn will check if the given error is a ResponseError and if it wraps this ResponseCode

type ResponseError added in v7.1.0

type ResponseError struct {
	ResponseCode
	Message string
}

ResponseError is used to wrap a ResponseCode into an error

func (ResponseError) Error added in v7.1.0

func (r ResponseError) Error() string

Error ensures the error interface is implemented for ResponseError

type SessionToken

type SessionToken struct {
	TokenID string `json:"tokenId,omitempty"`
}

SessionToken holds a session token

type ThingEndpointPayload

type ThingEndpointPayload struct {
	Token   string `json:"token"`
	Payload string `json:"payload,omitempty"`
}

ThingEndpointPayload wraps the payload destined for the Thing endpoint with the session token

Jump to

Keyboard shortcuts

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