onelogin

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 15 Imported by: 1

README

Onelogin

OneLogin client written in Go.

GoDoc Go Report Card

Getting Started

go get github.com/arkan/onelogin

Register an application on OneLogin

First you need to register a new application to have clientID and clientSecret credentials.

List users

c := onelogin.New(clientID, clientSecret, "us_or_eu", team)
users, err := c.User.GetUsers(context.Background())

See the documentation for all the available commands.

Licence

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the *http.Response. HTTP status codes ranging from 200 to 299 are considered are successes. Otherwise an error happen, and the error gets unmarshalled and returned into the error.

Types

type App

type App struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type AuthenticatedUser

type AuthenticatedUser struct {
	ID            int64  `json:"id"`
	Username      string `json:"username"`
	Email         string `json:"email"`
	FirstName     string `json:"firstname"`
	LastName      string `json:"lastname"`
	Devices       []Device
	IsMfaRequired bool
}

AuthenticatedUser contains user information for the Authentication.

func (*AuthenticatedUser) SetDevices

func (u *AuthenticatedUser) SetDevices(devices []Device)

func (*AuthenticatedUser) SetMfaRequirement

func (u *AuthenticatedUser) SetMfaRequirement(required bool)

type Client

type Client struct {
	BaseURL *url.URL

	// User agent used when communicating with the OneLogin api.
	UserAgent string

	Oauth *OauthService
	User  *UserService
	Role  *RoleService
	Group *GroupService
	SAML  *SAMLService

	sync.Mutex
	// contains filtered or unexported fields
}

A Client interacts with OneLogin.

func New

func New(clientID, clientSecret, shard, subdomain string) *Client

New returns a new OneLogin client.

func (*Client) AddAuthorization

func (c *Client) AddAuthorization(ctx context.Context, req *http.Request) error

AddAuthorization injects the Authorization header to the request. If the client doesn't has an oauthToken, a new token is issed. If the token is expired, it is automatically refreshed.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

The provided ctx must be non-nil. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest instantiate a new http.Request from a method, url and body. The body (if provided) is automatically Marshalled into JSON.

type Device

type Device struct {
	Id               int64  `json:"device_id"`
	DeviceType       string `json:"device_type"`
	ApiHostName      string `json:"duo_api_hostname"`
	SignatureRequest string `json:"duo_sig_request"`
}

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error

	Code    int64
	Type    string
	Message string
}

An ErrorResponse reports an error caused by an API request. Onelogin always returns Code, Type and a Message associated to the error. Example:

{
    "status": {
        "error": true,
        "code": 400,
        "type": "bad request",
        "message": "Content Type is not specified or specified incorrectly.
                    Content-Type header must be set to application/json"
    }
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Group

type Group struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type GroupService

type GroupService service

GroupService deals with OneLogin groups.

func (*GroupService) GetGroups

func (s *GroupService) GetGroups(ctx context.Context) ([]*Group, error)

GetGroups returns all the OneLogin groups.

type MFAResponse

type MFAResponse struct {
	StateToken  string   `json:"state_token"`
	User        SamlUser `json:"user"`
	Devices     []Device `json:"devices"`
	CallbackUrl string   `json:"callback_url"`
}

type OauthService

type OauthService service

OauthService handles communications with the authentication related methods on OneLogin.

func (*OauthService) Authenticate

func (s *OauthService) Authenticate(ctx context.Context, emailOrUsername string, password string) (*AuthenticatedUser, error)

Authenticate a user from an email(or username) and a password.

type Response

type Response struct {
	*http.Response

	PaginationAfterCursor  *string
	PaginationBeforeCursor *string
}

Response embeds a *http.Response as well as some Paginations values.

type Role

type Role struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type RoleService

type RoleService service

RoleService deals with OneLogin roles.

func (*RoleService) GetRoles

func (s *RoleService) GetRoles(ctx context.Context) ([]*Role, error)

GetRoles returns all the OneLogin Roles.

type SAMLService

type SAMLService service

func (*SAMLService) SamlAssertion

func (s *SAMLService) SamlAssertion(ctx context.Context, username, password, appID string) (*MFAResponse, error)

func (*SAMLService) VerifyFactor

func (s *SAMLService) VerifyFactor(ctx context.Context, otp, stateToken, appId, deviceId string) (string, error)

type SamlResponse

type SamlResponse struct {
	SamlString string
}

func (*SamlResponse) SetSamlString

func (s *SamlResponse) SetSamlString(saml string)

type SamlUser

type SamlUser struct {
	ID            int64  `json:"id"`
	Username      string `json:"username"`
	Email         string `json:"email"`
	FirstName     string `json:"firstname"`
	LastName      string `json:"lastname"`
	IsMfaRequired bool
}

func (*SamlUser) SetMfaRequirement

func (u *SamlUser) SetMfaRequirement(required bool)

type User

type User struct {
	ActivatedAt          string            `json:"activated_at"`
	CreatedAt            string            `json:"created_at"`
	Email                string            `json:"email"`
	Username             string            `json:"username"`
	FirstName            string            `json:"firstname"`
	GroupID              int64             `json:"group_id"`
	ID                   int64             `json:"id"`
	InvalidLoginAttempts int64             `json:"invalid_login_attempts"`
	InvitationSentAt     string            `json:"invitation_sent_at"`
	LastLogin            string            `json:"last_login"`
	LastName             string            `json:"lastname"`
	LockedUntil          string            `json:"locked_until"`
	Notes                string            `json:"notes"`
	OpenidName           string            `json:"openid_name"`
	LocaleCode           string            `json:"locale_code"`
	PasswordChangedAt    string            `json:"password_changed_at"`
	Phone                string            `json:"phone"`
	Status               int64             `json:"status"`
	UpdatedAt            string            `json:"updated_at"`
	DistinguishedName    string            `json:"distinguished_name"`
	ExternalID           string            `json:"external_id"`
	DirectoryID          int64             `json:"directory_id"`
	MemberOf             []string          `json:"member_of"`
	SamAccountName       string            `json:"samaccountname"`
	UserPrincipalName    string            `json:"userprincipalname"`
	ManagerAdID          int               `json:"manager_ad_id"`
	RoleIDs              []int64           `json:"role_id"`
	CustomAttributes     map[string]string `json:"custom_attributes"`
}

User represents a OneLogin user.

type UserService

type UserService service

UserService handles communications with the authentication related methods on OneLogin.

func (*UserService) GetApps

func (s *UserService) GetApps(ctx context.Context, id int64) (*[]App, error)

func (*UserService) GetUser

func (s *UserService) GetUser(ctx context.Context, id int64) (*User, error)

GetUser returns a OneLogin user.

func (*UserService) GetUsers

func (s *UserService) GetUsers(ctx context.Context) ([]*User, error)

GetUsers returns all the OneLogin users.

func (*UserService) UpdateCustomAttributes

func (s *UserService) UpdateCustomAttributes(ctx context.Context, id int64, attributes map[string]string) error

UpdateCustomAttributes returns a OneLogin user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL