# README
castle-go
castle-go is a Go library wrapping the https://castle.io API.
Note: This library is currently a prototype. To see fully supported SDKs, please refer to https://docs.castle.io/baseline/
Install
go get github.com/utilitywarehouse/castle-go
Usage
Providing own http client
castle.NewWithHTTPClient("secret-api-key", &http.Client{Timeout: time.Second * 2})
Tracking properties and traits
castle.Track(
castle.EventLoginSucceeded,
"user-123",
map[string]string{"prop1": "propValue1"},
map[string]string{"trait1": "traitValue1"},
castle.ContextFromRequest(req),
)
Tracking custom events
castle.Track(
castle.Event("custom-event"),
"user-123",
map[string]string{"prop1": "propValue1"},
map[string]string{"trait1": "traitValue1"},
castle.ContextFromRequest(req),
)
Adaptive authentication
decision, err := castle.Authenticate(
castle.EventLoginSucceeded,
"md-1",
map[string]string{"prop1": "propValue1"},
map[string]string{"trait1": "traitValue1"},
castle.ContextFromRequest(req),
)
Example
package main
import (
"log"
"net/http"
"github.com/utilitywarehouse/castle-go"
)
func main() {
cstl, err := castle.New("secret-api-key")
if err != nil {
log.Fatal(err)
}
http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// authenticate user then track with castle
decision, err := castle.AuthenticateSimple(
castle.EventLoginSucceeded,
"user-123",
castle.ContextFromRequest(r),
)
if err != nil {
log.Println(err)
}
if decision == castle.RecommendedActionChallenge {
// challenge with MFA and track with castle
err := cstl.TrackSimple(
castle.EventChallengeRequested,
"user-123",
castle.ContextFromRequest(r),
)
if err != nil {
log.Println(err)
}
// trigger off MFA path
}
w.WriteHeader(http.StatusNoContent)
}))
}
# Functions
ContextFromRequest builds castle context from current http.Request.
New creates a new castle client.
NewWithHTTPClient same as New but allows passing of http.Client with custom config.
# Constants
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://docs.castle.io/docs/events.
See https://castle.io/docs/authentication.
See https://castle.io/docs/authentication.
See https://castle.io/docs/authentication.
See https://castle.io/docs/authentication.
VERSION - current package version.
# Variables
FilterEndpoint defines the filter URL castle.io side.
HeaderAllowList keeps a list of headers that will be forwarded to castle.
RiskEndpoint defines the risk URL castle.io side.
# Structs
Castle encapsulates http client.
Context captures data from HTTP request.
No description provided by the author
No description provided by the author
WebhookBody encapsulates body of webhook notificationc coming from castle.io see https://castle.io/docs/webhooks.
# Type aliases
AuthenticationRecommendedAction encapsulates the 3 possible responses from auth call (allow, challenge, deny).
EventStatus is an enum defining the statuses for a given event.
EventType is an enum defining types of event castle tracks.