oktadance

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2019 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

README

oktadance

Provides a convenient API to do basic authentication against Okta.

TODO

  • Better MFA support (all that really works right now is okta verify)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleMultifactor

type ConsoleMultifactor struct {
	*readline.Instance
}

ConsoleMultifactor handles the user input

func NewConsoleMultifactor

func NewConsoleMultifactor() (*ConsoleMultifactor, error)

NewConsoleMultifactor creates a `MultiFactor` which interacts with a user on the console to complete multifactor auth

The exact console interface should be considered UNSTABLE. If you need a stable UI, you should implement `Multifactor` directly.

func (*ConsoleMultifactor) ReadCode

func (c *ConsoleMultifactor) ReadCode(Factor) (string, error)

ReadCode reads the MFA code when needed

func (*ConsoleMultifactor) RequestUsernamePassword

func (c *ConsoleMultifactor) RequestUsernamePassword() (username, password string, err error)

RequestUsernamePassword asks the user for their username and password

func (*ConsoleMultifactor) Select

func (c *ConsoleMultifactor) Select(factors []Factor) (Factor, error)

Select the factor to use for the challenge

type Dance

type Dance struct {
	// contains filtered or unexported fields
}

Dance performs the authentication & authorization dance with Okta

func New

func New(oktaDomain string, options ...Option) *Dance

New dance client. If you need to use `Authenticate` make sure to pass in a clientID option via `WithClientID`

func (*Dance) Authenticate

func (d *Dance) Authenticate(ctx context.Context, username, password string, mfa Multifactor) (SessionToken, error)

Authenticate authenticates the user against Okta and returns a `sessionToken`. The sessionToken needs to be given to the App which will then use `Authenticate` to authenticate the user for that App. The sessionToken is only usable once.

The `Multifactor` argument is used to complete multifactor authentication, if needed. If you *know* you won't need m,ultifactor authentication, it may be nil.

func (*Dance) Authorize

func (d *Dance) Authorize(ctx context.Context, sessionToken SessionToken) (SessionID, error)

Authorize establishes the session and returns the sid. It ensures the authentication token (sessionToken) is valid for the specific App (as identified by the clientId)

This method reuires a configured clientID as it verifies the pairing of the authenticated user and the application.

func (*Dance) CloseSession

func (d *Dance) CloseSession(ctx context.Context, sessionID SessionID) error

CloseSession closes the specified session

func (*Dance) RefreshSession

func (d *Dance) RefreshSession(ctx context.Context, sessionID SessionID) (*Session, error)

RefreshSession extends the lifetime of the current session

func (*Dance) Session

func (d *Dance) Session(ctx context.Context, sessionID SessionID) (*Session, error)

Session retrieves the user session information from Okta for a given SessionID (obtained via `Authenticate`). It can be run from an untrusted client, if that client has the sessionId. The sessionId is often referred to as the session cookie or sid.

type Factor

type Factor interface {
	ID() string
	FactorType() string
	Provider() string
	// contains filtered or unexported methods
}

Factor identifies a factor

type Multifactor

type Multifactor interface {

	// Select the factor to use for the challenge
	Select([]Factor) (Factor, error)

	// Obtain the MFA code
	ReadCode(Factor) (string, error)
}

Multifactor responds to MFA requests

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures the dance

func WithClientID

func WithClientID(clientID string) Option

WithClientID configures a clientID on the dance. This is needed for some operations. Those operations call it out. If all you are doing is authenticating, you should not need the client_id

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient allows you to specify your own http client. it is critical that this client be configured to not follow redirects: ```

httpClient := &http.Client{
    CheckRedirect: func(req *http.Request, via []*http.Request) error {
        return http.ErrUseLastResponse
    },
}

```

func WithLogger

func WithLogger(log func(...interface{})) Option

WithLogger passes in a logging function, such as `log.Println`, which will be used to log communication with Okta

func WithPrettyJSON

func WithPrettyJSON() Option

WithPrettyJSON forces pretty printed JSON on requests and in logs

type Session

type Session struct {
	ID                       string    `json:"id"`
	UserID                   string    `json:"userId"`
	Login                    string    `json:"login"`
	CreatedAt                time.Time `json:"createdAt"`
	ExpiresAt                time.Time `json:"expiresAt"`
	Status                   string    `json:"status"`
	LastPasswordVerification time.Time `json:"lastPasswordVerification"`
	LastFactorVerification   time.Time `json:"lastFactorVerification"`
	Amr                      []string  `json:"amr"`
	Idp                      struct {
		ID   string `json:"id"`
		Type string `json:"type"`
	} `json:"idp"`
	MfaActive bool `json:"mfaActive"`
	Links     struct {
		Self struct {
			Href  string `json:"href"`
			Hints struct {
				Allow []string `json:"allow"`
			} `json:"hints"`
		} `json:"self"`
		Refresh struct {
			Href  string `json:"href"`
			Hints struct {
				Allow []string `json:"allow"`
			} `json:"hints"`
		} `json:"refresh"`
		User struct {
			Name  string `json:"name"`
			Href  string `json:"href"`
			Hints struct {
				Allow []string `json:"allow"`
			} `json:"hints"`
		} `json:"user"`
	} `json:"_links"`
}

Session is an OKTA Session, see [Session Model](https://developer.okta.com/docs/reference/api/sessions/#session-model)

type SessionID

type SessionID string

SessionID is an OKTA sessionId or sid

type SessionToken

type SessionToken string

SessionToken is an OKTA sessionToken

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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