agent

package
v0.0.0-...-8dc4a41 Latest Latest
Warning

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

Go to latest
Published: May 25, 2018 License: Apache-2.0, LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

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

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

Functions

func LoginCookie

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

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

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.

Example
package main

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

func main() {
	// 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
	}
}
Output:

Types

type Agent

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

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

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

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

LegacyAgentResponse contains the response to a legacy agent login attempt.

Jump to

Keyboard shortcuts

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