Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define AuthLog struct #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 62 additions & 3 deletions admin/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,69 @@ type AuthLogResult struct {
}

// An AuthLog retrieved from https://duo.com/docs/adminapi#authentication-logs
// TODO: @Duo update this to be a struct based on the returned JSON structure of an authentication log.
type AuthLog map[string]interface{}
type AuthLog struct {
AccessDevice AccessDevice `json:"access_device"`
Alias string `json:"alias"`
Application Application `json:"application"`
AuthDevice AuthDevice `json:"auth_device"`
Email string `json:"email"`
EventType string `json:"event_type"`
Factor string `json:"factor"`
ISOTimestamp time.Time `json:"isotimestamp"`
OODSoftware string `json:"ood_software"`
Reason string `json:"reason"`
Result string `json:"result"`
Timestamp int64 `json:"timestamp"`
TxID string `json:"txid"`
User UserV2 `json:"user"`
}

// AccessDevice models a device that user uses to authenticate themselves.
type AccessDevice struct {
Browser string `json:"browser"`
BrowserVersion string `json:"browser_version"`
FlashVersion string `json:"flash_version"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
IsEncryptionEnabled string `json:"is_encryption_enabled"`
IsFirewallEnabled string `json:"is_firewall_enabled"`
IsPasswordSet string `json:"is_password_set"`
JavaVersion string `json:"java_version"`
Location Location `json:"location"`
OS string `json:"os"`
OSVersion string `json:"os_version"`
SecurityAgents string `json:"security_agents"`
}

// Application models information about the accessed application.
type Application struct {
Key string
Name string
}

// Location represents a location where the user authenticates themselves.
type Location struct {
City string `json:"city"`
Country string `json:"country"`
State string `json:"state"`
}

// AuthDevice models information about the device used to approve or
// deny authentication.
type AuthDevice struct {
IP string `json:"ip"`
Location Location `json:"location"`
Name string `json:"name"`
}

// UserV2 models information about the authenticating user.
type UserV2 struct {
Groups []string `json:"groups"`
Key string `json:"key"`
Name string `json:"name"`
}

// An AuthLogList holds retreived logs and V2 metadata used for pagination.
// An AuthLogList holds retrieved logs and V2 metadata used for pagination.
type AuthLogList struct {
Metadata LogListV2Metadata `json:"metadata"`
Logs []AuthLog `json:"authlogs"`
Expand Down
18 changes: 15 additions & 3 deletions admin/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ const getAuthLogsResponse = `{
"flash_version": "uninstalled",
"hostname": "null",
"ip": "169.232.89.219",
"is_encryption_enabled": "true",
"is_firewall_enabled": "true",
"is_password_set": "true",
"java_version": "uninstalled",
"location": {
"city": "Ann Arbor",
"country": "United States",
"state": "Michigan"
},
"os": "Mac OS X",
"os_version": "10.14.1"
"os_version": "10.14.1",
"security_agents": "unknown"
},
"alias": "",
"application": {
"key": "DIY231J8BR23QK4UKBY8",
"name": "Microsoft Azure Active Directory"
Expand All @@ -81,14 +86,21 @@ const getAuthLogsResponse = `{
},
"name": "My iPhone X (734-555-2342)"
},
"email": "[email protected]",
"event_type": "authentication",
"factor": "duo_push",
"isotimestamp": "2020-02-13T18:56:20.351346+00:00",
"ood_software": "null",
"reason": "user_approved",
"result": "success",
"timestamp": 1532951962,
"timestamp": 1581620180,
"trusted_endpoint_status": "not trusted",
"txid": "340a23e3-23f3-23c1-87dc-1491a23dfdbb",
"user": {
"groups": [
"Duo Users",
"CorpHQ Users"
],
"key": "DU3KC77WJ06Y5HIV7XKQ",
"name": "[email protected]"
}
Expand Down Expand Up @@ -134,7 +146,7 @@ func TestGetAuthLogs(t *testing.T) {
if length := len(result.Response.Logs); length != 1 {
t.Errorf("Expected 1 log, but got %d", length)
}
if txid := result.Response.Logs[0]["txid"]; txid != "340a23e3-23f3-23c1-87dc-1491a23dfdbb" {
if txid := result.Response.Logs[0].TxID; txid != "340a23e3-23f3-23c1-87dc-1491a23dfdbb" {
t.Errorf("Expected txid '340a23e3-23f3-23c1-87dc-1491a23dfdbb', but got %v", txid)
}
if next := result.Response.Metadata.GetNextOffset(); next == nil {
Expand Down