okta

package module
v0.0.0-...-5d88093 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: MIT Imports: 15 Imported by: 0

README

Okta

Okta client written in Go

GoDoc Go Report Card

Getting Started

go get github.com/arkan/okta

Create a new API Key on Okta

First you need to create a new api key on Okta to have a token.

List users

c := okta.New(apiToken, "organisation")
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

View Source
var (
	ErrAuthenticationFailed = errors.New("authentication failed. Please check username/password.")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL *url.URL

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

	User  *UserService
	Group *GroupService
	// contains filtered or unexported fields
}

A Client interacts with Okta.

func New

func New(apiToken, organisation string) *Client

New returns a new Okta 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 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.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type GetUsersOptions

type GetUsersOptions struct {
	// PerPage is the max number of result in a page,
	// max value defined by Okta is 200.
	// If set to less than 1 or more than 200, it will be reset to 200.
	PerPage int

	// Pages is the max number of pages to retrieve.
	// If 0, it will page until there's no more results to retrieve.
	Pages int
}

GetUsersOptions allows to specify query options.

type Group

type Group struct {
	ID   string
	Name string
}

type GroupService

type GroupService service

GroupService deals with Okta groups.

func (*GroupService) GetGroupMembership

func (s *GroupService) GetGroupMembership(ctx context.Context, groupID string) ([]*User, error)

GetGroupMembership returns all users from a group.

func (*GroupService) GetGroups

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

GetGroups returns all the Okta groups.

func (*GroupService) GetUserGroups

func (s *GroupService) GetUserGroups(ctx context.Context, userID string) ([]*Group, error)

type Response

type Response struct {
	*http.Response
}

Response embeds a *http.Response.

type User

type User struct {
	ID              string            `json:"id"`
	Status          string            `json:"status"`
	LastLogin       string            `json:"last_login"`
	Created         string            `json:"created"`
	LastUpdated     string            `json:"last_updated"`
	PasswordChanged string            `json:"password_changed"`
	Profile         map[string]string `json:"profile"`
}

User represents a Okta user.

type UserService

type UserService service

UserService handles users operations.

func (*UserService) Authenticate

func (s *UserService) Authenticate(ctx context.Context, username, password, relayState string) (*User, error)

Authenticate the user with username and password. relayState can be used to add additional information.

func (*UserService) GetUser

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

GetUser returns a user.

func (*UserService) GetUsers

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

GetUsers returns all the users.

func (*UserService) UpdateCustomAttributes

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

UpdateCustomAttributes returns a user.

Jump to

Keyboard shortcuts

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