session

package
Version: v0.0.0-...-ee64981 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package session allows direct access to the SDK session management API. Use it to obtain a Single Sign On (SSO) token from Access Management.

This example shows how to use a username and password to authenticate and obtain an SSO token:

// Connect directly to AM
amURL, _ := url.Parse("https://am.example.com:8443/am")

// Create a session by authenticating with a username and password
session, _ := builder.Session().
    ConnectTo(amURL).
    InRealm("/all-the-things").
    WithTree("auth-tree").
    AuthenticateWith(
        callback.NameHandler{Name: "my-device"},
        callback.PasswordHandler{Password: "password"}).
    Create()

// The SSO token can be used to authorize REST requests directly with AM
ssoToken := session.Token()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {

	// ConnectTo the server at the given URL.
	// Supports http(s) for connecting to AM and coap(s) for connecting to the Thing Gateway.
	ConnectTo(url *url.URL) Builder

	// InRealm specifies the path to the AM realm in which to authenticate.
	// The realm is not required if connecting to the Thing Gateway. If provided it will be ignored.
	InRealm(realm string) Builder

	// WithTree sets the name of the AM authentication tree that will be used for authentication.
	// The tree is not required if connecting to the Thing Gateway. If provided it will be ignored.
	WithTree(tree string) Builder

	// AuthenticateWith the supplied callback handlers when creating the session. The provided handlers must
	// match those configured in the AM authentication tree.
	AuthenticateWith(handlers ...callback.Handler) Builder

	// TimeoutRequestAfter sets the timeout on the communications between the Thing and AM or the Thing Gateway.
	TimeoutRequestAfter(d time.Duration) Builder

	// Create a Session instance and make an authentication request to AM. The callback handlers provided
	// will be used to satisfy the callbacks received from the AM authentication process.
	Create() (Session, error)
}

type Session

type Session interface {

	// Token returns the session token.
	Token() string

	// Valid returns true if the session is valid.
	Valid() (bool, error)

	// Logout the session.
	Logout() error
}

Session represents an authenticated session with AM.

Source Files

Jump to

Keyboard shortcuts

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