Skip to content

Commit

Permalink
services implemented missing mfa
Browse files Browse the repository at this point in the history
  • Loading branch information
Jmfwolf committed Jun 13, 2023
1 parent 320ed3d commit af5af6b
Show file tree
Hide file tree
Showing 15 changed files with 668 additions and 80 deletions.
8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ func main() {
return
}
fmt.Println("App List:", appList)
description := "Test App Description"
newApp := models.App{Name: "Go SDK Demo App", Description: &description, ConnectorID: 2}
createdApp, err := ol.CreateApp(&newApp)
if err != nil {
fmt.Println("Failed to create app:", err)
return
}
fmt.Println("Created App:", createdApp)

}
2 changes: 1 addition & 1 deletion internal/models/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package models

type App struct {
ID int32 `json:"id"`
ID int32 `json:"id,omitempty"`
ConnectorID int32 `json:"connector_id"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Expand Down
26 changes: 26 additions & 0 deletions internal/models/mfa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package models

type GenerateSAMLTokenRequest struct {
UsernameOrEmail string `json:"username_or_email"`
Password string `json:"password"`
AppID string `json:"app_id"`
Subdomain string `json:"subdomain"`
IPAddress string `json:"ip_address,omitempty"`
}

type VerifyMFATokenRequest struct {
AppID string `json:"app_id"`
DeviceID string `json:"device_id"`
StateToken string `json:"state_token"`
OTPToken string `json:"otp_token,omitempty"`
DoNotNotify bool `json:"do_not_notify,omitempty"`
}

type EnrollFactorRequest struct {
FactorID int `json:"factor_id"`
DisplayName string `json:"display_name"`
ExpiresIn string `json:"expires_in,omitempty"`
Verified bool `json:"verified,omitempty"`
RedirectTo string `json:"redirect_to,omitempty"`
CustomMessage string `json:"custom_message,omitempty"`
}
8 changes: 4 additions & 4 deletions internal/models/smart_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ type Options struct {

// SmartHookEnvVarQuery represents available query parameters
type SmartHookEnvVarQuery struct {
Limit string
Page string
Cursor string
Type string
Limit string `json:"limit,omitempty"`
Page string `json:"page,omitempty"`
Cursor string `json:"cursor,omitempty"`
Type string `json:"type,omitempty"`
}

// EnvVar represents an Environment Variable to be associated with a SmartHook
Expand Down
16 changes: 8 additions & 8 deletions internal/models/user_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package models

// UserMappingsQuery represents available query parameters for mappings
type UserMappingsQuery struct {
Limit string
Page string
Cursor string
HasCondition string
HasConditionType string
HasAction string
HasActionType string
Enabled string
Limit string `json:"limit,omitempty"`
Page string `json:"page,omitempty"`
Cursor string `json:"cursor,omitempty"`
HasCondition string `json:"has_condition,omitempty"`
HasConditionType string `json:"has_condition_type,omitempty"`
HasAction string `json:"has_action,omitempty"`
HasActionType string `json:"has_action_type,omitempty"`
Enabled string `json:"enabled,omitempty"`
}

// UserMapping is the contract for User Mappings.
Expand Down
2 changes: 1 addition & 1 deletion internal/utilities/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// else return error
func CheckHTTPResponse(resp *http.Response) (interface{}, error) {
// Check if the request was successful
if resp.StatusCode != http.StatusOK {
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
return nil, fmt.Errorf("request failed with status: %d", resp.StatusCode)
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/onelogin/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,15 @@ func (sdk *OneloginSDK) DeleteAppRule(id, ruleID int, queryParams map[string]str
}
return utl.CheckHTTPResponse(resp)
}

func (sdk *OneloginSDK) GetAppUsers(appID int) (interface{}, error) {
p, err := utl.BuildAPIPath(AppPath, appID, "users")
if err != nil {
return nil, err
}
resp, err := sdk.Client.Get(&p, nil)
if err != nil {
return nil, err
}
return utl.CheckHTTPResponse(resp)
}
28 changes: 28 additions & 0 deletions pkg/onelogin/groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package onelogin

import utl "github.com/onelogin/onelogin-go-sdk/internal/utilities"

const (
GroupsPath = "api/1/groups"
)

func (sdk *OneloginSDK) GetGroupByID(groupID int) (interface{}, error) {
p, err := utl.BuildAPIPath(GroupsPath, groupID)
if err != nil {
return nil, err
}
resp, err := sdk.Client.Get(&p, nil)
if err != nil {
return nil, err
}
return utl.CheckHTTPResponse(resp)
}

func (sdk *OneloginSDK) GetGroups() (interface{}, error) {
p := GroupsPath
resp, err := sdk.Client.Get(&p, nil)
if err != nil {
return nil, err
}
return utl.CheckHTTPResponse(resp)
}
49 changes: 49 additions & 0 deletions pkg/onelogin/mfa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package onelogin

import (
"github.com/onelogin/onelogin-go-sdk/internal/models"
utl "github.com/onelogin/onelogin-go-sdk/internal/utilities"
)

const (
MFAPath string = "api/2/mfa/users"
)

// https://<subdomain>/api/2/mfa/users/<user_id>/factors
func (sdk *OneloginSDK) GetAuthFactors(userID int) (interface{}, error) {
p, err := utl.BuildAPIPath(MFAPath, userID, "factors")
if err != nil {
return nil, err
}
resp, err := sdk.Client.Get(&p, nil)
if err != nil {
return nil, err
}
return utl.CheckHTTPResponse(resp)
}

// https://<subdomain>/api/2/mfa/users/<user_id>/registrations
func (sdk *OneloginSDK) EnrollMFAFactor(factor models.EnrollFactorRequest, userID int) (interface{}, error) {
p, err := utl.BuildAPIPath(MFAPath, userID, "registrations")
if err != nil {
return nil, err
}
resp, err := sdk.Client.Post(&p, factor)
if err != nil {
return nil, err
}
return utl.CheckHTTPResponse(resp)
}

// https://<subdomain>/api/2/mfa/users/<user_id>/registrations/<registration_id>
func (sdk *OneloginSDK) VerifyMFAEnrollment(userID, registrationID, otp int) (interface{}, error) {
p, err := utl.BuildAPIPath(MFAPath, userID, "registrations", registrationID)
if err != nil {
return nil, err
}
resp, err := sdk.Client.Put(&p, otp)
if err != nil {
return nil, err
}
return utl.CheckHTTPResponse(resp)
}
65 changes: 0 additions & 65 deletions pkg/onelogin/onelogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,6 @@ func (sdk *OneloginSDK) GetToken() (string, error) {
return accessTk, nil
}

// MFA-related endpoints
func (sdk *OneloginSDK) ActivateMFAFactor(userID int, deviceID int) {
// Implementation for Activate MFA Factor endpoint
}

func (sdk *OneloginSDK) EnrollMFAFactor(userID int) {
// Implementation for Enroll MFA Factor endpoint
}

// Group-related endpoints
func (sdk *OneloginSDK) GetGroupByID(groupID int) {
// Implementation for Get Group By ID endpoint
}

func (sdk *OneloginSDK) GetGroups() {
// Implementation for Get Groups endpoint
}

// Invite-related endpoints
func (sdk *OneloginSDK) GenerateInviteLink() {
// Implementation for Generate Invite Link endpoint
}
Expand All @@ -56,23 +37,16 @@ func (sdk *OneloginSDK) SendInviteLink() {
// Implementation for Send Invite Link endpoint
}

// Connector-related endpoints
func (sdk *OneloginSDK) ListConnectors() {
// Implementation for List Connectors endpoint
}

// App User-related endpoints
func (sdk *OneloginSDK) GetAppUsers(appID int) {
// Implementation for Get App Users endpoint
}

func (sdk *OneloginSDK) CreateDeviceVerification(userID int) {
// Implementation for Create Device Verification endpoint
}
func (sdk *OneloginSDK) CreateFactorRegistration(userID int) {}
func (sdk *OneloginSDK) DeleteEnrolledFactor(userID int, deviceID int) {}
func (sdk *OneloginSDK) GenerateOTP(userID int) {}
func (sdk *OneloginSDK) GetAuthFactors(userID int) {}
func (sdk *OneloginSDK) GetAuthenticationDevices(userID int) {}
func (sdk *OneloginSDK) GetUserRegistration(userID int, registrationID int) {}
func (sdk *OneloginSDK) GetUserVerification(userID int, verificationID int) {}
Expand All @@ -83,42 +57,3 @@ func (sdk *OneloginSDK) GetEnrolledFactors(userID int) {
func (sdk *OneloginSDK) GetMFAFactors(userID int) {}
func (sdk *OneloginSDK) RemoveMFAFactor(userID int, deviceID int) {}
func (sdk *OneloginSDK) VerifyMFAFactor(userID int, deviceID int) {}

func (sdk *OneloginSDK) AddPrivilegeToRole(privilegeID int, roleID int) {}
func (sdk *OneloginSDK) AssignUsersToPrivilege(privilegeID int) {}
func (sdk *OneloginSDK) CreatePrivilege() {}
func (sdk *OneloginSDK) DeletePrivilege(privilegeID int) {}
func (sdk *OneloginSDK) DeleteRoleFromPrivilege(privilegeID int, roleID int) {}
func (sdk *OneloginSDK) GetAssignedUsers(privilegeID int) {}
func (sdk *OneloginSDK) GetPrivilege(privilegeID int) {}
func (sdk *OneloginSDK) GetPrivilegeRoles(privilegeID int) {}
func (sdk *OneloginSDK) ListPrivileges() {}
func (sdk *OneloginSDK) RemovePrivilegeFromUser(privilegeID int, userID int) {}
func (sdk *OneloginSDK) UpdatePrivilege(privilegeID int) {}

func (sdk *OneloginSDK) GenerateSAMLAssertion() {}
func (sdk *OneloginSDK) VerifyFactorSAML() {}

func (sdk *OneloginSDK) CreateEnvironmentVariable() {}
func (sdk *OneloginSDK) CreateHook() {}
func (sdk *OneloginSDK) DeleteEnvironmentVariable(envVarID int) {}
func (sdk *OneloginSDK) DeleteHook(hookID int) {}
func (sdk *OneloginSDK) GetEnvironmentVariable(envVarID int) {}
func (sdk *OneloginSDK) GetHook(hookID int) {}
func (sdk *OneloginSDK) GetHookLogs(hookID int) {}
func (sdk *OneloginSDK) ListEnvironmentVariables() {}
func (sdk *OneloginSDK) ListSmartHooks() {}
func (sdk *OneloginSDK) UpdateEnvironmentVariable(envVarID int) {}
func (sdk *OneloginSDK) UpdateSmartHook(hookID int) {}
func (sdk *OneloginSDK) CreateMapping() {}
func (sdk *OneloginSDK) DeleteMapping(mappingID int) {}
func (sdk *OneloginSDK) GetMapping(mappingID int) {}
func (sdk *OneloginSDK) ListMappings() {}
func (sdk *OneloginSDK) ListActions() {}
func (sdk *OneloginSDK) SortMappings() {}
func (sdk *OneloginSDK) UpdateMapping(mappingID int) {}
func (sdk *OneloginSDK) AddRolesToUser(userID int) {}
func (sdk *OneloginSDK) GetCustomAttributes() {}

func (sdk *OneloginSDK) RemoveUserRole(userID int) {}
func (sdk *OneloginSDK) SetUserState(userID int) {}
Loading

0 comments on commit af5af6b

Please sign in to comment.