uaa

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

README

go-uaa Travis-CI GoDoc Report card

Overview

go-uaa is a client library for the UAA API.

Usage
go get -u github.com/cloudfoundry-community/go-uaa
Experimental
  • For the foreseeable future, releases will be in the v0.x.y range
  • You should expect breaking changes until v1.x.y releases occur
  • Notifications of breaking changes will be made via release notes associated with each tag
  • You should use a vendoring solution (like dep) until the vgo proposal is fully integrated with the go toolchain
Contributing

Pull requests welcome.

Documentation

Index

Constants

View Source
const (
	// OK is healthy.
	OK = HealthStatus("ok")
	// ERROR is unhealthy.
	ERROR = HealthStatus("health_error")
)
View Source
const (
	REFRESHTOKEN      = GrantType("refresh_token")
	AUTHCODE          = GrantType("authorization_code")
	IMPLICIT          = GrantType("implicit")
	PASSWORD          = GrantType("password")
	CLIENTCREDENTIALS = GrantType("client_credentials")
)

Valid GrantType values.

View Source
const (
	// SortAscending sorts in ascending order.
	SortAscending = SortOrder("ascending")
	// SortDescending sorts in descending order.
	SortDescending = SortOrder("descending")
)

Variables

This section is empty.

Functions

func BuildSubdomainURL added in v0.0.7

func BuildSubdomainURL(target string, zoneID string) (*url.URL, error)

BuildSubdomainURL returns a URL that optionally includes the zone ID as a host prefix. If the target does not include a scheme, https will be used.

func BuildTargetURL added in v0.0.7

func BuildTargetURL(target string) (*url.URL, error)

BuildTargetURL returns a URL. If the target does not include a scheme, https / will be used.

Types

type API added in v0.0.7

type API struct {
	AuthenticatedClient   *http.Client
	UnauthenticatedClient *http.Client
	TargetURL             *url.URL
	SkipSSLValidation     bool
	Verbose               bool
	ZoneID                string
}

API is a client to the UAA API.

func NewWithAuthorizationCode added in v0.0.7

func NewWithAuthorizationCode(target string, zoneID string, clientID string, clientSecret string, code string, skipSSLValidation bool, tokenFormat TokenFormat) (*API, error)

NewWithAuthorizationCode builds an API that uses the authorization code grant to get a token for use with the UAA API.

You can supply an http.Client because this function has side-effects (a token is requested from the target).

If you do not supply an http.Client,

http.Client{Transport: http.DefaultTransport}

will be used.

func NewWithClientCredentials added in v0.0.7

func NewWithClientCredentials(target string, zoneID string, clientID string, clientSecret string, tokenFormat TokenFormat) (*API, error)

NewWithClientCredentials builds an API that uses the client credentials grant to get a token for use with the UAA API.

func NewWithPasswordCredentials added in v0.0.7

func NewWithPasswordCredentials(target string, zoneID string, clientID string, clientSecret string, username string, password string, tokenFormat TokenFormat) (*API, error)

NewWithPasswordCredentials builds an API that uses the password credentials grant to get a token for use with the UAA API.

func (*API) ActivateUser added in v0.0.7

func (a *API) ActivateUser(userID string, userMetaVersion int) error

ActivateUser activates the user with the given user ID http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#patch.

func (*API) CreateUser added in v0.0.7

func (a *API) CreateUser(user User) (*User, error)

CreateUser creates the given user http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#create-4.

func (*API) DeactivateUser added in v0.0.7

func (a *API) DeactivateUser(userID string, userMetaVersion int) error

DeactivateUser deactivates the user with the given user ID http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#patch.

func (*API) DeleteUser added in v0.0.7

func (a *API) DeleteUser(userID string) (*User, error)

DeleteUser deletes the user with the given user ID http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#delete-4.

func (*API) GetInfo added in v0.0.7

func (a *API) GetInfo() (*Info, error)

GetInfo gets server information http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#server-information-2.

func (*API) GetMe added in v0.0.7

func (a *API) GetMe() (*UserInfo, error)

GetMe retrieves the UserInfo for the current user.

func (*API) GetUser added in v0.0.7

func (a *API) GetUser(userID string) (*User, error)

GetUser with the given userID http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#get-3.

func (*API) GetUserByUsername added in v0.0.7

func (a *API) GetUserByUsername(username, origin, attributes string) (*User, error)

GetUserByUsername gets the user with the given username http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#list-with-attribute-filtering.

func (*API) ListAllUsers added in v0.0.7

func (a *API) ListAllUsers(filter, sortBy, attributes string, sortOrder SortOrder) ([]User, error)

ListAllUsers retrieves UAA users http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#list-with-attribute-filtering.

func (*API) ListUsers added in v0.0.7

func (a *API) ListUsers(filter string, sortBy string, attributes string, sortOrder SortOrder, startIndex int, itemsPerPage int) ([]User, Page, error)

ListUsers with the given filter, sortBy, attributes, sortOrder, startIndex (1-based), and count (default 100). If successful, ListUsers returns the users and the total itemsPerPage of users for all pages. If unsuccessful, ListUsers returns the error.

func (*API) UpdateUser added in v0.0.7

func (a *API) UpdateUser(user User) (*User, error)

UpdateUser updates the given user http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#update-4.

type Approval

type Approval struct {
	UserID        string `json:"userId,omitempty"`
	ClientID      string `json:"clientId,omitempty"`
	Scope         string `json:"scope,omitempty"`
	Status        string `json:"status,omitempty"`
	LastUpdatedAt string `json:"lastUpdatedAt,omitempty"`
	ExpiresAt     string `json:"expiresAt,omitempty"`
}

Approval is a record of the user's explicit approval or rejection for an application's request for delegated permissions.

type AuthContext added in v0.0.2

type AuthContext struct {
	ClientID  string    `json:"client_id"`
	GrantType GrantType `json:"grant_type"`
	Username  string    `json:"username"`
	TokenResponse
}

AuthContext is a container for the token used to access UAA.

func NewContextWithToken

func NewContextWithToken(accessToken string) AuthContext

NewContextWithToken creates a new config with the given token.

type AuthenticatedRequestor added in v0.0.2

type AuthenticatedRequestor struct{}

AuthenticatedRequestor makes requests that are authenticated.

func (AuthenticatedRequestor) Delete added in v0.0.2

func (ag AuthenticatedRequestor) Delete(client *http.Client, config Config, path string, query string) ([]byte, error)

Delete makes a delete request.

func (AuthenticatedRequestor) Get added in v0.0.2

func (ag AuthenticatedRequestor) Get(client *http.Client, config Config, path string, query string) ([]byte, error)

Get makes a get request.

func (AuthenticatedRequestor) PatchJSON added in v0.0.2

func (ag AuthenticatedRequestor) PatchJSON(client *http.Client, config Config, path string, query string, body interface{}, extraHeaders map[string]string) ([]byte, error)

PatchJSON makes a patch request.

func (AuthenticatedRequestor) PostForm added in v0.0.2

func (ag AuthenticatedRequestor) PostForm(client *http.Client, config Config, path string, query string, body map[string]string) ([]byte, error)

PostForm makes a post request.

func (AuthenticatedRequestor) PostJSON added in v0.0.2

func (ag AuthenticatedRequestor) PostJSON(client *http.Client, config Config, path string, query string, body interface{}) ([]byte, error)

PostJSON makes a post request.

func (AuthenticatedRequestor) PutJSON added in v0.0.2

func (ag AuthenticatedRequestor) PutJSON(client *http.Client, config Config, path string, query string, body interface{}) ([]byte, error)

PutJSON makes a put request.

type AuthorizationCodeClient

type AuthorizationCodeClient struct {
	ClientID     string
	ClientSecret string
}

AuthorizationCodeClient is used to authenticate with the authorization server.

func (AuthorizationCodeClient) RequestToken

func (acc AuthorizationCodeClient) RequestToken(httpClient *http.Client, config Config, format TokenFormat, code string, redirectURI string) (TokenResponse, error)

RequestToken gets a token from the token endpoint.

type Client added in v0.0.2

type Client struct {
	ClientID             string   `json:"client_id,omitempty"`
	ClientSecret         string   `json:"client_secret,omitempty"`
	Scope                []string `json:"scope,omitempty"`
	ResourceIDs          []string `json:"resource_ids,omitempty"`
	AuthorizedGrantTypes []string `json:"authorized_grant_types,omitempty"`
	RedirectURI          []string `json:"redirect_uri,omitempty"`
	Authorities          []string `json:"authorities,omitempty"`
	TokenSalt            string   `json:"token_salt,omitempty"`
	AllowedProviders     []string `json:"allowedproviders,omitempty"`
	DisplayName          string   `json:"name,omitempty"`
	LastModified         int64    `json:"lastModified,omitempty"`
	RequiredUserGroups   []string `json:"required_user_groups,omitempty"`
	AccessTokenValidity  int64    `json:"access_token_validity,omitempty"`
	RefreshTokenValidity int64    `json:"refresh_token_validity,omitempty"`
}

Client is a UAA client http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#clients.

func (*Client) Validate added in v0.0.2

func (c *Client) Validate() error

Validate returns nil if the client is valid, or an error if it is invalid.

type ClientCredentialsClient

type ClientCredentialsClient struct {
	ClientID     string
	ClientSecret string
}

ClientCredentialsClient is used to authenticate with the authorization server.

func (ClientCredentialsClient) RequestToken

func (cc ClientCredentialsClient) RequestToken(httpClient *http.Client, config Config, format TokenFormat) (TokenResponse, error)

RequestToken gets a token from the token endpoint.

type ClientManager

type ClientManager struct {
	HTTPClient *http.Client
	Config     Config
}

ClientManager allows you to interact with the Clients resource.

func (*ClientManager) ChangeSecret

func (cm *ClientManager) ChangeSecret(id string, newSecret string) error

ChangeSecret updates the secret with the given value for the client with the given id http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#change-secret.

func (*ClientManager) Create

func (cm *ClientManager) Create(client Client) (Client, error)

Create the given client http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#create-6.

func (*ClientManager) Delete

func (cm *ClientManager) Delete(id string) (Client, error)

Delete the client with the given ID http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#delete-6.

func (*ClientManager) Get

func (cm *ClientManager) Get(id string) (Client, error)

Get the client with the given ID http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#retrieve-3.

func (*ClientManager) List

func (cm *ClientManager) List() ([]Client, error)

List all clients.

func (*ClientManager) Update

func (cm *ClientManager) Update(client Client) (Client, error)

Update the given client http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#update-6.

type Config

type Config struct {
	Verbose          bool
	ZoneSubdomain    string
	Targets          map[string]Target
	ActiveTargetName string
}

Config is used to access the UAA API.

func NewConfig

func NewConfig() Config

NewConfig creates a config that is initialized with an empty map of targets.

func NewConfigWithServerURL

func NewConfigWithServerURL(url string) Config

NewConfigWithServerURL creates a new config with the given URL.

func (*Config) AddContext

func (c *Config) AddContext(newContext AuthContext)

AddContext adds the given context to the active target.

func (*Config) AddTarget

func (c *Config) AddTarget(newTarget Target)

AddTarget adds the given target to the config, and sets the active target to the given target.

func (Config) GetActiveContext

func (c Config) GetActiveContext() AuthContext

GetActiveContext gets the active context.

func (Config) GetActiveTarget

func (c Config) GetActiveTarget() Target

GetActiveTarget gets the active target.

type CurlManager

type CurlManager struct {
	HTTPClient *http.Client
	Config     Config
}

CurlManager allows you to make arbitrary requests to the UAA API.

func (CurlManager) Curl

func (cm CurlManager) Curl(path, method, data string, headers []string) (resHeaders, resBody string, err error)

Curl makes a request to the UAA API with the given path, method, data, and headers.

type Email added in v0.0.2

type Email struct {
	Value   string `json:"value,omitempty"`
	Primary *bool  `json:"primary,omitempty"`
}

Email is an email address.

type GrantType

type GrantType string

GrantType is a type of oauth2 grant.

type Group added in v0.0.2

type Group struct {
	ID          string        `json:"id,omitempty"`
	Meta        *Meta         `json:"meta,omitempty"`
	DisplayName string        `json:"displayName,omitempty"`
	ZoneID      string        `json:"zoneId,omitempty"`
	Description string        `json:"description,omitempty"`
	Members     []GroupMember `json:"members,omitempty"`
	Schemas     []string      `json:"schemas,omitempty"`
}

Group is a container for users and groups.

type GroupManager

type GroupManager struct {
	HTTPClient *http.Client
	Config     Config
}

GroupManager allows you to interact with the Groups resource.

func (GroupManager) AddMember

func (gm GroupManager) AddMember(groupID, userID string) error

AddMember adds the user with the given ID to the group with the given ID.

func (GroupManager) Create

func (gm GroupManager) Create(group Group) (Group, error)

Create the given group http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#create-5.

func (GroupManager) Delete

func (gm GroupManager) Delete(groupID string) (Group, error)

Delete the group with the given ID http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#delete-5.

func (GroupManager) Get

func (gm GroupManager) Get(id string) (Group, error)

Get the group with the given ID http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#retrieve-2.

func (GroupManager) GetByName

func (gm GroupManager) GetByName(name, attributes string) (Group, error)

GetByName gets the group with the given name http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#list-4.

func (GroupManager) List

func (gm GroupManager) List(filter, sortBy, attributes string, sortOrder SortOrder) ([]Group, error)

List groups http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#list-4.

func (GroupManager) Update

func (gm GroupManager) Update(group Group) (Group, error)

Update the given group http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#update-5.

type GroupMember added in v0.0.2

type GroupMember struct {
	Origin string `json:"origin,omitempty"`
	Type   string `json:"type,omitempty"`
	Value  string `json:"value,omitempty"`
}

GroupMember is a user or a group.

type HealthStatus added in v0.0.2

type HealthStatus string

HealthStatus is either ok or an error.

func Health

func Health(target Target) (HealthStatus, error)

Health gets the health of the UAA API.

type Info

type Info struct {
	App            uaaApp              `json:"app"`
	Links          uaaLinks            `json:"links"`
	Prompts        map[string][]string `json:"prompts"`
	ZoneName       string              `json:"zone_name"`
	EntityID       string              `json:"entityID"`
	CommitID       string              `json:"commit_id"`
	Timestamp      string              `json:"timestamp"`
	IdpDefinitions map[string]string   `json:"idpDefinitions"`
}

Info is information about the UAA server.

type JWK

type JWK struct {
	Kty   string `json:"kty"`
	E     string `json:"e,omitempty"`
	Use   string `json:"use"`
	Kid   string `json:"kid"`
	Alg   string `json:"alg"`
	Value string `json:"value"`
	N     string `json:"n,omitempty"`
}

JWK represents a JSON Web Key (https://tools.ietf.org/html/rfc7517).

func TokenKey

func TokenKey(client *http.Client, config Config) (JWK, error)

TokenKey retrieves a JWK from the token_key endpoint (http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#token-key-s).

func TokenKeys

func TokenKeys(client *http.Client, config Config) ([]JWK, error)

TokenKeys gets the JSON Web Token signing keys with the given client and config.

type Keys

type Keys struct {
	Keys []JWK `json:"keys"`
}

Keys is a slice of JSON Web Keys.

type Meta added in v0.0.2

type Meta struct {
	Version      int    `json:"version,omitempty"`
	Created      string `json:"created,omitempty"`
	LastModified string `json:"lastModified,omitempty"`
}

Meta describes the version and timestamps for a resource.

type Page added in v0.0.7

type Page struct {
	StartIndex   int `json:"startIndex"`
	ItemsPerPage int `json:"itemsPerPage"`
	TotalResults int `json:"totalResults"`
}

Page represents a page of information returned from the UAA API.

type PaginatedClientList

type PaginatedClientList struct {
	Resources    []Client `json:"resources"`
	StartIndex   int      `json:"startIndex"`
	ItemsPerPage int      `json:"itemsPerPage"`
	TotalResults int      `json:"totalResults"`
	Schemas      []string `json:"schemas"`
}

PaginatedClientList is the response from the API for a single page of clients.

type PaginatedGroupList

type PaginatedGroupList struct {
	Resources    []Group  `json:"resources"`
	StartIndex   int      `json:"startIndex"`
	ItemsPerPage int      `json:"itemsPerPage"`
	TotalResults int      `json:"totalResults"`
	Schemas      []string `json:"schemas"`
}

PaginatedGroupList is the response from the API for a single page of groups.

type PhoneNumber

type PhoneNumber struct {
	Value string `json:"value"`
}

PhoneNumber is a phone number for a user.

type RefreshTokenClient

type RefreshTokenClient struct {
	ClientID     string
	ClientSecret string
}

RefreshTokenClient is used to authenticate with the authorization server.

func (RefreshTokenClient) RequestToken

func (rc RefreshTokenClient) RequestToken(httpClient *http.Client, config Config, format TokenFormat, refreshToken string) (TokenResponse, error)

RequestToken gets a token from the token endpoint.

type Requestor added in v0.0.2

type Requestor interface {
	Get(client *http.Client, config Config, path string, query string) ([]byte, error)
	Delete(client *http.Client, config Config, path string, query string) ([]byte, error)
	PostForm(client *http.Client, config Config, path string, query string, body map[string]string) ([]byte, error)
	PostJSON(client *http.Client, config Config, path string, query string, body interface{}) ([]byte, error)
	PutJSON(client *http.Client, config Config, path string, query string, body interface{}) ([]byte, error)
}

Requestor makes requests with a client.

type ResourceOwnerPasswordClient

type ResourceOwnerPasswordClient struct {
	ClientID     string
	ClientSecret string
	Username     string
	Password     string
}

ResourceOwnerPasswordClient is used to authenticate with the authorization server.

func (ResourceOwnerPasswordClient) RequestToken

func (rop ResourceOwnerPasswordClient) RequestToken(httpClient *http.Client, config Config, format TokenFormat) (TokenResponse, error)

RequestToken gets a token from the token endpoint.

type SortOrder added in v0.0.2

type SortOrder string

SortOrder defines the sort order when listing users or groups.

type Target

type Target struct {
	BaseURL           string
	SkipSSLValidation bool
	Contexts          map[string]AuthContext
	ActiveContextName string
}

Target is a UAA endpoint.

func NewTarget

func NewTarget() Target

NewTarget creates a target that is initialized with an empty map of contexts.

func (Target) GetActiveContext

func (t Target) GetActiveContext() AuthContext

GetActiveContext gets the active context.

type TokenFormat

type TokenFormat int

TokenFormat is the format of a token.

const (
	OpaqueToken TokenFormat = iota
	JSONWebToken
)

Valid TokenFormat values.

func (TokenFormat) String added in v0.0.7

func (t TokenFormat) String() string

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	IDToken      string `json:"id_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int32  `json:"expires_in"`
	Scope        string `json:"scope"`
	JTI          string `json:"jti"`
}

TokenResponse is a token.

type UnauthenticatedRequestor added in v0.0.2

type UnauthenticatedRequestor struct{}

UnauthenticatedRequestor makes requests that are unauthenticated.

func (UnauthenticatedRequestor) Delete added in v0.0.2

func (ug UnauthenticatedRequestor) Delete(client *http.Client, config Config, path string, query string) ([]byte, error)

Delete makes a delete request.

func (UnauthenticatedRequestor) Get added in v0.0.2

func (ug UnauthenticatedRequestor) Get(client *http.Client, config Config, path string, query string) ([]byte, error)

Get makes a get request.

func (UnauthenticatedRequestor) PatchJSON added in v0.0.2

func (ug UnauthenticatedRequestor) PatchJSON(client *http.Client, config Config, path string, query string, body interface{}) ([]byte, error)

PatchJSON makes a patch request.

func (UnauthenticatedRequestor) PostForm added in v0.0.2

func (ug UnauthenticatedRequestor) PostForm(client *http.Client, config Config, path string, query string, body map[string]string) ([]byte, error)

PostForm makes a post request.

func (UnauthenticatedRequestor) PostJSON added in v0.0.2

func (ug UnauthenticatedRequestor) PostJSON(client *http.Client, config Config, path string, query string, body interface{}) ([]byte, error)

PostJSON makes a post request.

func (UnauthenticatedRequestor) PutJSON added in v0.0.2

func (ug UnauthenticatedRequestor) PutJSON(client *http.Client, config Config, path string, query string, body interface{}) ([]byte, error)

PutJSON makes a put request.

type User added in v0.0.2

type User struct {
	ID                   string        `json:"id,omitempty"`
	Password             string        `json:"password,omitempty"`
	ExternalID           string        `json:"externalId,omitempty"`
	Meta                 *Meta         `json:"meta,omitempty"`
	Username             string        `json:"userName,omitempty"`
	Name                 *UserName     `json:"name,omitempty"`
	Emails               []Email       `json:"emails,omitempty"`
	Groups               []UserGroup   `json:"groups,omitempty"`
	Approvals            []Approval    `json:"approvals,omitempty"`
	PhoneNumbers         []PhoneNumber `json:"phoneNumbers,omitempty"`
	Active               *bool         `json:"active,omitempty"`
	Verified             *bool         `json:"verified,omitempty"`
	Origin               string        `json:"origin,omitempty"`
	ZoneID               string        `json:"zoneId,omitempty"`
	PasswordLastModified string        `json:"passwordLastModified,omitempty"`
	PreviousLogonTime    int           `json:"previousLogonTime,omitempty"`
	LastLogonTime        int           `json:"lastLogonTime,omitempty"`
	Schemas              []string      `json:"schemas,omitempty"`
}

User is a UAA user http://docs.cloudfoundry.org/api/uaa/version/4.14.0/index.html#get-3.

type UserGroup added in v0.0.2

type UserGroup struct {
	Value   string `json:"value,omitempty"`
	Display string `json:"display,omitempty"`
	Type    string `json:"type,omitempty"`
}

UserGroup is a group that a user belongs to.

type UserInfo added in v0.0.2

type UserInfo struct {
	UserID            string   `json:"user_id"`
	Sub               string   `json:"sub"`
	Username          string   `json:"user_name"`
	GivenName         string   `json:"given_name"`
	FamilyName        string   `json:"family_name"`
	Email             string   `json:"email"`
	PhoneNumber       []string `json:"phone_number"`
	PreviousLoginTime int64    `json:"previous_logon_time"`
	Name              string   `json:"name"`
}

UserInfo is a protected resource required for OpenID Connect compatibility. The response format is defined here: https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse.

type UserName added in v0.0.2

type UserName struct {
	FamilyName string `json:"familyName,omitempty"`
	GivenName  string `json:"givenName,omitempty"`
}

UserName is a person's name.

Directories

Path Synopsis
Package passwordcredentials implements the OAuth2.0 "password credentials" token flow.
Package passwordcredentials implements the OAuth2.0 "password credentials" token flow.

Jump to

Keyboard shortcuts

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