macaroon-bakery.v2-unstable: gopkg.in/macaroon-bakery.v2-unstable/httpbakery/agent Index | Examples | Files

package agent

import "gopkg.in/macaroon-bakery.v2-unstable/httpbakery/agent"

Package agent enables non-interactive (agent) login using macaroons. To enable agent authorization with a given httpbakery.Client c against a given third party discharge server URL u:

SetUpAuth(c, u, agentUsername)

Index

Examples

Package Files

agent.go cookie.go protocol.go

Variables

var ErrNoAgentLoginCookie = errgo.New("no agent-login cookie found")

ErrNoAgentLoginCookie is the error returned when the expected agent login cookie has not been found.

func LoginCookie Uses

func LoginCookie(req *http.Request) (username string, key *bakery.PublicKey, err error)

LoginCookie returns details of the agent login cookie from the given request. If no agent-login cookie is found, it returns an ErrNoAgentLoginCookie error.

func SetInteraction Uses

func SetInteraction(e *httpbakery.Error, loginURL string)

SetInteraction sets agent interaction information on the given error, which should be an interaction-required error to be returned from a discharge request.

The given URL (which may be relative to the discharger location) will be the subject of a GET request by the client to fetch the agent macaroon that, when discharged, can act as the discharge token.

func SetUpAuth Uses

func SetUpAuth(client *httpbakery.Client, authInfo *AuthInfo) error

SetUpAuth sets up agent authentication on the given client. If this is called several times on the same client, earlier calls will take precedence over later calls when there's a URL and username match for both.

Code:

// In practice the key would be read from persistent
// storage.
key, err := bakery.GenerateKey()
if err != nil {
    // handle error
}

client := httpbakery.NewClient()
err = agent.SetUpAuth(client, &agent.AuthInfo{
    Key: key,
    Agents: []agent.Agent{{
        URL:      "http://foo.com",
        Username: "agent-username",
    }},
})
if err != nil {
    // handle error
}

type Agent Uses

type Agent struct {
    // URL holds the URL associated with the agent.
    URL string `json:"url" yaml:"url"`
    // Username holds the username to use for the agent.
    Username string `json:"username" yaml:"username"`
}

Agent represents an agent that can be used for agent authentication.

type AuthInfo Uses

type AuthInfo struct {
    Key    *bakery.KeyPair `json:"key,omitempty" yaml:"key,omitempty"`
    Agents []Agent         `json:"agents" yaml:"agents"`
}

AuthInfo holds the agent information required to set up agent authentication information. It holds the agent's private key and information about the username associated with each known agent-authentication server.

type InteractionInfo Uses

type InteractionInfo struct {
    // LoginURL holds the URL from which to acquire
    // a macaroon that can be used to complete the agent
    // login. To acquire the macaroon, make a POST
    // request to the URL with user and public-key
    // parameters.
    LoginURL string `json:"login-url"`
}

InteractionInfo holds the information expected in the agent interaction entry in an interaction-required error.

type LegacyAgentResponse Uses

type LegacyAgentResponse struct {
    AgentLogin bool `json:"agent-login"`
}

LegacyAgentResponse contains the response to a legacy agent login attempt.

Package agent imports 13 packages (graph) and is imported by 1 packages. Updated 2017-12-21. Refresh now. Tools for package owners.