forked from castle/castle-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package castle | ||
|
||
type Event struct { | ||
EventType EventType | ||
EventStatus EventStatus | ||
} | ||
|
||
// EventType is an enum defining types of event castle tracks. | ||
type EventType string | ||
|
||
// See https://docs.castle.io/docs/events | ||
const ( | ||
EventTypeLogin EventType = "$login" | ||
EventTypeRegistration EventType = "$registration" | ||
EventTypeProfileUpdate EventType = "$profile_update" | ||
EventTypeProfileReset EventType = "$profile_reset" | ||
EventTypePasswordResetRequest EventType = "$password_reset_request" | ||
EventTypeChallenge EventType = "$challenge" | ||
EventTypeLogout EventType = "&logout" | ||
) | ||
|
||
// EventStatus is an enum defining the statuses for a given event. | ||
type EventStatus string | ||
|
||
// See https://docs.castle.io/docs/events | ||
const ( | ||
EventStatusAttempted EventStatus = "$attempted" | ||
EventStatusSucceeded EventStatus = "$succeeded" | ||
EventStatusFailed EventStatus = "$failed" | ||
EventStatusRequested EventStatus = "$requested" | ||
) | ||
|
||
// RecommendedAction encapsulates the 3 possible responses from auth call (allow, challenge, deny). | ||
type RecommendedAction string | ||
|
||
// See https://castle.io/docs/authentication | ||
const ( | ||
RecommendedActionNone RecommendedAction = "" | ||
RecommendedActionAllow RecommendedAction = "allow" | ||
RecommendedActionChallenge RecommendedAction = "challenge" | ||
RecommendedActionDeny RecommendedAction = "deny" | ||
) | ||
|
||
// Request wraps the Castle required data for to the pkg's Risk and Filter methods. | ||
type Request struct { | ||
Context *Context | ||
Event Event | ||
User User | ||
Properties map[string]string | ||
} | ||
|
||
// Context captures data from HTTP request. | ||
type Context struct { | ||
IP string `json:"ip"` | ||
Headers map[string]string `json:"headers"` | ||
RequestToken string `json:"request_token"` | ||
} | ||
|
||
type User struct { | ||
ID string `json:"id"` | ||
Email string `json:"email,omitempty"` | ||
Phone string `json:"phone,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
RegisteredAt string `json:"registered_at,omitempty"` | ||
Traits map[string]string `json:"traits,omitempty"` | ||
} | ||
|
||
type castleAPIRequest struct { | ||
Type EventType `json:"type"` | ||
Status EventStatus `json:"status"` | ||
RequestToken string `json:"request_token"` | ||
User User `json:"user"` | ||
Context *Context `json:"context"` | ||
Properties map[string]string `json:"properties,omitempty"` | ||
} | ||
|
||
type castleAPIResponse struct { | ||
Type string `json:"type"` | ||
Message string `json:"message"` | ||
Risk float32 `json:"risk"` | ||
Policy struct { | ||
Name string `json:"name"` | ||
ID string `json:"id"` | ||
RevisionID string `json:"revision_id"` | ||
Action string `json:"action"` | ||
} `json:"policy"` | ||
Device struct { | ||
Token string `json:"token"` | ||
} `json:"device"` | ||
} |