Help us shape the future of Go! Take the 2026 Go Developer Survey

onelogin

package module
v0.0.0-...-35d2d88 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2016 License: MIT Imports: 11 Imported by: 0

README

type OneLogin struct {
	// Allow custom base URL to override the generated URL
	CustomURL string

	// OneLogin service shard (eu, us, etc)
	Shard string

	// Token struct for managing the OAuth token
	Token *OneLogin_Token

	SubDomain     string
	Client_id     string
	Client_secret string
}
func (o *OneLogin) Authenticate(username string, password string, token string) error
func (o *OneLogin) GetUrl(uri string, args ...string) string
func (o *OneLogin) Get_AppsForUser(userId int) ([]OneLoginApp, error)
func (o *OneLogin) Get_Role_Id(role string) (int, error)
func (o *OneLogin) Get_Roles(name string) ([]OneLoginRole, error)
func (o *OneLogin) Get_RolesForUser(userId int) ([]int, error)
func (o *OneLogin) Get_Token() (*OneLogin_Token, error)
func (o *OneLogin) Get_Users(filter map[string]string) (*[]OneLoginUser, error)
func (o *OneLogin) Get_UsersWithRole(role string) ([]OneLoginUser, error)
func (o *OneLogin) Set_CustomAttribute(userid int, attributeName string, attributeValue string) error
func (o *OneLogin) VerifyToken(device_id string, state_token string, token string) error

Documentation

Index

Constants

View Source
const (
	USER_GET_USERS      = "api/1/users"
	USER_GET_APPS       = "api/1/users/%s/apps"
	USER_GET_USER_ROLES = "api/1/users/%s/roles"

	USERS_SET_ATTRIBUTE    = "api/1/users/%s/set_custom_attributes"
	USER_CUSTOM_ATTRIBUTES = "api/1/users/custom_attributes"

	USER_AUTHENTICATE  = "api/1/login/auth"
	USER_VERIFY_FACTOR = "api/1/login/verify_factor"
)
View Source
const LoggerModule = "onelogin"
View Source
const (
	OAUTH_ENDPOINT = "auth/oauth2"
)
View Source
const ONELOGIN_URL = "https://api.%s.onelogin.com"
View Source
const (
	ROLE_GET_ROLES = "api/1/roles"
)

Variables

This section is empty.

Functions

func ErrorOcurred

func ErrorOcurred(err error) error

func Headers

func Headers(authorization string) map[string]string

* Compile headers for the API call *

func LogFormat

func LogFormat() logging.Formatter

func SetLogLevel

func SetLogLevel(level logging.Level)

func StderrBackend

func StderrBackend(prefix string) logging.Backend

func StderrFormatter

func StderrFormatter(prefix string)

Types

type AuthResponse

type AuthResponse struct {
	Status ResponseStatus `json:"status"`
	Data   []struct {
		State_token string `json:"state_token"`
		Devices     []struct {
			Device_type string `json:"device_type"`
			Device_id   int    `json:"device_id"`
		} `json:devices`
		User struct {
			Lastname  string `json:"lastname"`
			Username  string `json:"username"`
			Email     string `json:"email"`
			Id        int    `json:"id"`
			Firstname string `json:"firstname"`
		} `json:user`
		Callback_url string `json:"callback_url"`
	} `json:data`
}

Object representing the JSON response for a user authentication request.

type AuthenticationRequest

type AuthenticationRequest struct {
	Username_or_email string `json:"username_or_email"`
	Password          string `json:"password"`
	Subdomain         string `json:"subdomain"`
}

Object representing an HTTP request body for verifying user credentials.

type GetRoleResponse

type GetRoleResponse struct {
	Status     ResponseStatus     `json:"status"`
	Pagination ResponsePagination `json:"pagination"`
	Data       []OneLoginRole     `json:"data"`
}

Object representing the result of a get user request.

type GetUserAppsResponse

type GetUserAppsResponse struct {
	Status     ResponseStatus     `json:"status"`
	Pagination ResponsePagination `json:"pagination"`
	Data       []OneLoginApp      `json:"data"`
}

Object representing the result of a get user apps request.

type GetUserResponse

type GetUserResponse struct {
	Status     ResponseStatus     `json:"status"`
	Pagination ResponsePagination `json:"pagination"`
	Data       []OneLoginUser     `json:"data"`
}

Object representing the result of a get user request.

type GetUserRolesResponse

type GetUserRolesResponse struct {
	Status     ResponseStatus     `json:"status"`
	Pagination ResponsePagination `json:"pagination"`
	Data       []int              `json:"data"`
}

Object representing the result of a get user roles request.

type HttpClient

type HttpClient struct {
	Url     string            // Request URL (http://www.google.com/)
	Params  map[string]string // Map of headers
	Headers map[string]string // Map of query parameters
}

func (*HttpClient) CreateUrl

func (h *HttpClient) CreateUrl(requrl string, parameters map[string]string) string

*

** Generate a full request URL with provided parameters.
**
** requrl      Base URL without required parameters.
** parameters  Map of key value pairs to add to the URL as query parameters.
*

func (*HttpClient) EncodeBody

func (h *HttpClient) EncodeBody(requestBody interface{}) ([]byte, error)

*

** Encode the request body object to json.
**
** requestBody   Interface for passing in arbitrary objects that will be converted to json for transport
*

func (*HttpClient) Go

func (h *HttpClient) Go(method string, body io.Reader, respObj interface{}) ([]byte, error)

*

** Perform the actual HTTP request, returning whatever response comes back as a byte array.
**
** @method    The HTTP method to perform (GET, POST, PUT, DELETE, HEAD, OPTIONS, etc)
** @body      An io.Reader object containing the body to pass along with the request
** @respObj   The response object that we want data unmarshaled into, or nil if not needed.
*

func (*HttpClient) Request

func (h *HttpClient) Request(method string, reqObj interface{}, respObj interface{}) (interface{}, error)

*

** Perform an HTTP operation.
**
** @reqObj Interface for passing in arbitrary objects that will be converted to JSON for transport
** @resObj Interface for returning arbitrary objects containing the unmarshaled response data
*

type OAuthGrantBody

type OAuthGrantBody struct {
	Grant_type    string `json:"grant_type"`
	Refresh_token string `json:"refresh_token,omitempty"`
	Access_token  string `json:"access_token,omitempty"`
	Client_id     string `json:"client_id,omitempty"`
	Client_secret string `json:"client_secret,omitempty"`
}

OAuth grant body

type OAuthResponse

type OAuthResponse struct {
	Status ResponseStatus `json:status`
	Data   []struct {
		Access_token  string `json:"access_token"`
		Account_id    int    `json:"account_id"`
		Created_at    string `json:"created_at"`
		Expires_in    int    `json:"expires_in"`
		Refresh_token string `json:"refresh_token"`
		Token_type    string `json:"token_type"`
	} `json:"data"`
}

Object representing the JSON response for an OAuth authentication request.

type OneLogin

type OneLogin struct {
	// Allow custom base URL to override the generated URL
	CustomURL string

	// OneLogin service shard (eu, us, etc)
	Shard string

	// Token struct for managing the OAuth token
	Token *OneLogin_Token

	SubDomain     string
	Client_id     string
	Client_secret string
}

The main OneLogin structure.

func New

func New(shard string, client_id string, client_secret string, subdomain string, loglevel logging.Level) *OneLogin

func (*OneLogin) Authenticate

func (o *OneLogin) Authenticate(username string, password string, token string) error

*

** Performs an authentication request for a user.  An optional MFA token can be passed in with
** the assumption that it will be required.  If no token is passed in and one is required,
** authentication will fail.
*

func (*OneLogin) GetUrl

func (o *OneLogin) GetUrl(uri string, args ...string) string

GetUrl creates a URL given the URI and any given args. Returns a URL

func (*OneLogin) Get_AppsForUser

func (o *OneLogin) Get_AppsForUser(userId int) ([]OneLoginApp, error)

Get_AppsForUser returns all apps that a user has assigned. Returns a slice of OneLoginApp objects and an error if any errors occur

func (*OneLogin) Get_Role_Id

func (o *OneLogin) Get_Role_Id(role string) (int, error)

func (*OneLogin) Get_Roles

func (o *OneLogin) Get_Roles(name string) ([]OneLoginRole, error)

Get all roles, or specify a name for a single role. Get_Roles("") => Get all roles Get_Roles("operations") => Get operations role

func (*OneLogin) Get_RolesForUser

func (o *OneLogin) Get_RolesForUser(userId int) ([]int, error)

Get_RolesForUser returns all apps that a user has assigned. Returns a slice of integers representing role ids and an error if any errors occur

func (*OneLogin) Get_Token

func (o *OneLogin) Get_Token() (*OneLogin_Token, error)

Convenience function to always return a token, generating or refreshing if necessary. TODO: Enable refreshing when necessary.

func (*OneLogin) Get_Users

func (o *OneLogin) Get_Users(filter map[string]string) (*[]OneLoginUser, error)

Get_Users returns all users that match the filter. Allowed filters include:

directory_id, email, external_id, firstname, id, manager_ad_id,
role_id, samaccountname, since, until, username, userprincipalname

filter can also include sort, fields, and limit. See OneLogin documentation for more details (https://developers.onelogin.com/api-docs/1/users/get-users)

OneLogin's API only returns at most 50 objects per call. Until we enable paging on this end, we are going to page through and fetch all user objects.

Returns a slice of OneLoginUser objects and an error if any error occurred.

func (*OneLogin) Get_UsersWithRole

func (o *OneLogin) Get_UsersWithRole(role string) ([]OneLoginUser, error)

Get_UsersWithRole returns all users that have the specified role. If no role is given (empty string) then all users will be returned. Returns a slice of OneLoginUser objects and an error if any error occurred.

func (*OneLogin) SetLogLevel

func (o *OneLogin) SetLogLevel(loglevel logging.Level)

func (*OneLogin) Set_CustomAttribute

func (o *OneLogin) Set_CustomAttribute(userid int, attributeName string, attributeValue string) error

Set_CustomAttribute sets the custom attribute (attributeName) with the value (attributeValue) for the user with the given ID. Returns an error if any error occurred.

func (*OneLogin) VerifyToken

func (o *OneLogin) VerifyToken(device_id string, state_token string, token string) error

*

** Verify an MFA token
*

type OneLoginApp

type OneLoginApp struct {
	Id          int    `json:"id"`
	Name        string `json:"name"`
	Icon        string `json:"icon"`
	Provisioned string `json:"provisioned"`
	Extension   bool   `json:"extension"`
	Login_id    int32  `json:"login_id"`
	Personal    bool   `json:"personal"`
}

Object representing a single App description

type OneLoginRole

type OneLoginRole struct {
	Id   int    `json:"id"`
	Name string `json:"name,omitempty"`
}

type OneLoginUser

type OneLoginUser struct {
	Activated_at           string            `json:"activated_at"`
	Created_at             string            `json:"created_at"`
	Email                  string            `json:"email"`
	Username               string            `json:"username"`
	Firstname              string            `json:"firstname"`
	Group_id               int               `json:"group_id"`
	Id                     int               `json:"id"`
	Invalid_login_attempts int               `json:"invalid_login_attempts"`
	Invitation_sent_at     string            `json:"invitation_sent_at"`
	Last_login             string            `json:"last_login"`
	Lastname               string            `json:"lastname"`
	Locked_until           string            `json:"locked_until"`
	Notes                  string            `json:"notes"`
	Openid_name            string            `json:"openid_name"`
	Locale_code            string            `json:"locale_code"`
	Password_changed_at    string            `json:"password_changed_at"`
	Phone                  string            `json:"phone"`
	Status                 int               `json:"status"`
	Updated_at             string            `json:"updated_at"`
	Distinguished_name     string            `json:"distinguished_name"`
	External_id            int               `json:'external_id'`
	Directory_id           int               `json:"directory_id"`
	Member_of              []string          `json:"member_of"`
	Samaccountname         string            `json:"samaccountname"`
	Userprincipalname      string            `json:"userprincipalname"`
	Manager_ad_id          int               `json:"manager_ad_id"`
	Role_id                []int             `json:"role_id"`
	Custom_attributes      map[string]string `json:"custom_attributes"`
}

Object representing user data.

type OneLogin_Token

type OneLogin_Token struct {
	Endpoint      string
	Client_id     string
	Client_secret string
	Access_token  string `json:"access_token"`
	Created_at    string `json:"created_at"`
	Expires_in    int    `json:"expires_in"`
	Refresh_token string `json:"refresh_token"`
}

OAuth token

func (*OneLogin_Token) Get

func (t *OneLogin_Token) Get() error

Fetch an OAuth token from the OneLogin API to be used for resource authentication.

func (*OneLogin_Token) Refresh

func (t *OneLogin_Token) Refresh() error

Refresh an OAuth token from the OneLogin API to be used for resource authentication.

func (*OneLogin_Token) Revoke

func (t *OneLogin_Token) Revoke() error

Revoke an OAuth token from the OneLogin API.

type ResponsePagination

type ResponsePagination struct {
	Before_cursor string `json:"before_cursor"`
	After_cursor  string `json:"after_cursor"`
	Previous_link string `json:"previous_link"`
	Next_link     string `json:"next_link"`
}

Object representing the pagination data for a request.

type ResponseStatus

type ResponseStatus struct {
	Code    int    `json:"code"`
	Error   bool   `json:"error"`
	Message string `json:"message"`
	Type    string `json:"type"`
}

Object representing the JSON "status" portion of a request response. All responses contain a "status" object.

type SetCustomAttributeRequest

type SetCustomAttributeRequest struct {
	Custom_Attributes map[string]string `json:"custom_attributes"`
}

type VerifyTokenRequest

type VerifyTokenRequest struct {
	Device_id   string `json:"device_id"`
	State_token string `json:"state_token"`
	Otp_token   string `json:"otp_token"`
}

Object representing an HTTP request body for verifying an OTP token.

Jump to

Keyboard shortcuts

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