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

fix: refactor authorizer v2 #162

Merged
merged 5 commits into from
Nov 11, 2024
Merged
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
52 changes: 27 additions & 25 deletions api/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package auth

import (
"net/url"

"github.com/SSHcom/privx-sdk-go/api/filters"
"github.com/SSHcom/privx-sdk-go/api/response"
"github.com/SSHcom/privx-sdk-go/restapi"
Expand Down Expand Up @@ -47,75 +49,75 @@ func (c *Auth) CreateIdpClient(idpClient *IdpClient) (response.Identifier, error
}

// UpdateIdpClient updates existing identity provider client configuration definition.
func (c *Auth) UpdateIdpClient(idpClient *IdpClient, idpId string) error {
func (c *Auth) UpdateIdpClient(idpClient *IdpClient, idpID string) error {
_, err := c.api.
URL("/auth/api/v1/idp/clients/%s", idpId).
URL("/auth/api/v1/idp/clients/%s", idpID).
Put(&idpClient)

return err
}

// GetIdpClient get existing identity provider client configuration.
func (c *Auth) GetIdpClient(idpId string) (*IdpClient, error) {
func (c *Auth) GetIdpClient(idpID string) (*IdpClient, error) {
idpClient := &IdpClient{}

_, err := c.api.
URL("/auth/api/v1/idp/clients/%s", idpId).
URL("/auth/api/v1/idp/clients/%s", idpID).
Get(&idpClient)

return idpClient, err
}

// DeleteIdpClient delete identity provider client configuration by Id.
func (c *Auth) DeleteIdpClient(idpId string) error {
// DeleteIdpClient delete identity provider client configuration by id.
func (c *Auth) DeleteIdpClient(idpID string) error {
_, err := c.api.
URL("/auth/api/v1/idp/clients/%s", idpId).
URL("/auth/api/v1/idp/clients/%s", idpID).
Delete()

return err
}

// RegenerateIdpClientConfig regenerates client_id and client_secret
// for OIDC identity provider client configuration.
func (c *Auth) RegenerateIdpClientConfig(idpId string) (*IdpClientConfig, error) {
func (c *Auth) RegenerateIdpClientConfig(idpID string) (*IdpClientConfig, error) {
clientConfig := &IdpClientConfig{}

_, err := c.api.
URL("/auth/api/v1/idp/clients/%s/regenerate", idpId).
URL("/auth/api/v1/idp/clients/%s/regenerate", idpID).
Post(nil, &clientConfig)

return clientConfig, err
}

// MARK: Session Storage
// GetUserSessions get valid sessions by userID.
func (c *Auth) GetUserSessions(userId string, opts ...filters.Option) (*response.ResultSet[Session], error) {
func (c *Auth) GetUserSessions(userID string, opts ...filters.Option) (*response.ResultSet[Session], error) {
userSessions := &response.ResultSet[Session]{}
params := filters.Default()
params := url.Values{}

for _, opt := range opts {
opt(&params)
}

_, err := c.api.
URL("/auth/api/v1/sessionstorage/users/%s/sessions", userId).
URL("/auth/api/v1/sessionstorage/users/%s/sessions", userID).
Query(params).
Get(&userSessions)

return userSessions, err
}

// GetSourceSessions get valid sessions by sourceID.
func (c *Auth) GetSourceSessions(sourceId string, opts ...filters.Option) (*response.ResultSet[Session], error) {
func (c *Auth) GetSourceSessions(sourceID string, opts ...filters.Option) (*response.ResultSet[Session], error) {
sourceSessions := &response.ResultSet[Session]{}
params := filters.Default()
params := url.Values{}

for _, opt := range opts {
opt(&params)
}

_, err := c.api.
URL("/auth/api/v1/sessionstorage/sources/%s/sessions", sourceId).
URL("/auth/api/v1/sessionstorage/sources/%s/sessions", sourceID).
Query(params).
Get(&sourceSessions)

Expand All @@ -125,7 +127,7 @@ func (c *Auth) GetSourceSessions(sourceId string, opts ...filters.Option) (*resp
// SearchSessions searches for sessions
func (c *Auth) SearchSessions(search *SessionSearch, opts ...filters.Option) (*response.ResultSet[Session], error) {
sessions := &response.ResultSet[Session]{}
params := filters.Default()
params := url.Values{}

for _, opt := range opts {
opt(&params)
Expand All @@ -139,19 +141,19 @@ func (c *Auth) SearchSessions(search *SessionSearch, opts ...filters.Option) (*r
return sessions, err
}

// TerminateSession terminates single session by Id.
func (c *Auth) TerminateSession(sessionId string) error {
// TerminateSession terminates single session by id.
func (c *Auth) TerminateSession(sessionID string) error {
_, err := c.api.
URL("/auth/api/v1/sessionstorage/sessions/%s/terminate", sessionId).
URL("/auth/api/v1/sessionstorage/sessions/%s/terminate", sessionID).
Post(nil)

return err
}

// TerminateUserSessions terminates all sessions for a user.
func (store *Auth) TerminateUserSessions(userId string) error {
func (store *Auth) TerminateUserSessions(userID string) error {
_, err := store.api.
URL("/auth/api/v1/sessionstorage/users/%s/sessions/terminate", userId).
URL("/auth/api/v1/sessionstorage/users/%s/sessions/terminate", userID).
Post(nil)

return err
Expand All @@ -169,20 +171,20 @@ func (store *Auth) Logout() error {

// MARK: Mobile Gateway
// GetUserPairedDevices get users paired devices.
func (store *Auth) GetUserPairedDevices(userId string) (*response.ResultSet[Device], error) {
func (store *Auth) GetUserPairedDevices(userID string) (*response.ResultSet[Device], error) {
devices := &response.ResultSet[Device]{}

_, err := store.api.
URL("/auth/api/v1/users/%s/devices", userId).
URL("/auth/api/v1/users/%s/devices", userID).
Get(devices)

return devices, err
}

// UnpairUserDevice unpair users device.
func (store *Auth) UnpairUserDevice(userId, deviceId string) error {
func (store *Auth) UnpairUserDevice(userID, deviceID string) error {
_, err := store.api.
URL("/auth/api/v1/users/%s/devices/%s", userId, deviceId).
URL("/auth/api/v1/users/%s/devices/%s", userID, deviceID).
Delete()

return err
Expand Down
19 changes: 10 additions & 9 deletions api/auth/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import "time"

// IdpClient identity provider client definition.
type IdpClient struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
Created time.Time `json:"created,omitempty"`
Updated time.Time `json:"updated,omitempty"`
IdpType string `json:"idp_type"`
IDPType string `json:"idp_type"`
OIDCIssuer string `json:"oidc_issuer,omitempty"`
OIDCAudience []string `json:"oidc_audience"`
OIDCClientId string `json:"oidc_client_id,omitempty"`
OIDCClientID string `json:"oidc_client_id,omitempty"`
OIDCClientSecret string `json:"oidc_client_secret,omitempty"`
OIDCScopesEnabled []string `json:"oidc_scopes_enabled"`
OIDCResponseTypesSupported []string `json:"oidc_response_types_supported,omitempty"`
Expand All @@ -35,6 +35,7 @@ type IdpClient struct {
OIDCRefreshTokenValidInMinutes int `json:"oidc_refresh_token_valid_in_minutes,omitempty"`
UserFilter string `json:"user_filter,omitempty"`
Enabled bool `json:"enabled"`
ContainerRequired bool `json:"container_required,omitempty"`
}

// IdpClientConfig identity provider client config definition.
Expand All @@ -45,15 +46,15 @@ type IdpClientConfig struct {

// Session session definition
type Session struct {
Id string `json:"id"`
UserId string `json:"user_id"`
SourceId string `json:"source_id"`
ID string `json:"id"`
UserID string `json:"user_id"`
SourceID string `json:"source_id"`
Domain string `json:"domain"`
Username string `json:"username"`
RemoteAddr string `json:"remote_addr"`
UserAgent string `json:"user_agent"`
Type string `json:"type"`
ParentSessionId string `json:"parent_session_id,omitempty"`
ParentSessionID string `json:"parent_session_id,omitempty"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Expires time.Time `json:"expires"`
Expand All @@ -77,13 +78,13 @@ type SessionPasswordPolicy struct {
// SessionSearch session search request parameter definition.
type SessionSearch struct {
Keywords string `json:"keywords,omitempty"`
UserId string `json:"user_id,omitempty"`
UserID string `json:"user_id,omitempty"`
Type string `json:"type,omitempty"`
}

// Device paired mobile gateway device definition.
type Device struct {
Id string `json:"id"`
ID string `json:"id"`
OS string `json:"os"`
Name string `json:"name"`
Activated string `json:"activated"`
Expand Down
Loading
Loading