client

package
v0.9.16 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package client implements the OAuth 2.0 Client functionality and provides http handlers, http clients and storage adapters.

Index

Constants

View Source
const (
	ClientsResource = "rn:hydra:clients"
	ClientResource  = "rn:hydra:clients:%s"
	Scope           = "hydra.clients"
)
View Source
const (
	ClientsHandlerPath = "/clients"
)

Variables

This section is empty.

Functions

func TestHelperClientAuthenticate added in v0.9.3

func TestHelperClientAuthenticate(k string, m Manager) func(t *testing.T)

func TestHelperClientAutoGenerateKey added in v0.9.1

func TestHelperClientAutoGenerateKey(k string, m Storage) func(t *testing.T)

func TestHelperCreateGetDeleteClient added in v0.9.1

func TestHelperCreateGetDeleteClient(k string, m Storage) func(t *testing.T)

Types

type Client

type Client struct {
	// ID is the id for this client.
	ID string `json:"id" gorethink:"id"`

	// Name is the human-readable string name of the client to be presented to the
	// end-user during authorization.
	Name string `json:"client_name" gorethink:"client_name"`

	// Secret is the client's secret. The secret will be included in the create request as cleartext, and then
	// never again. The secret is stored using BCrypt so it is impossible to recover it. Tell your users
	// that they need to write the secret down as it will not be made available again.
	Secret string `json:"client_secret,omitempty" gorethink:"client_secret"`

	// RedirectURIs is an array of allowed redirect urls for the client, for example: http://mydomain/oauth/callback .
	RedirectURIs []string `json:"redirect_uris" gorethink:"redirect_uris"`

	// GrantTypes is an array of grant types the client is allowed to use.
	//
	// Pattern: client_credentials|authorize_code|implicit|refresh_token
	GrantTypes []string `json:"grant_types" gorethink:"grant_types"`

	// ResponseTypes is an array of the OAuth 2.0 response type strings that the client can
	// use at the authorization endpoint.
	//
	// Pattern: id_token|code|token
	ResponseTypes []string `json:"response_types" gorethink:"response_types"`

	// Scope is a string containing a space-separated list of scope values (as
	// described in Section 3.3 of OAuth 2.0 [RFC6749]) that the client
	// can use when requesting access tokens.
	//
	// Pattern: ([a-zA-Z0-9\.]+\s)+
	Scope string `json:"scope" gorethink:"scope"`

	// Owner is a string identifying the owner of the OAuth 2.0 Client.
	Owner string `json:"owner" gorethink:"owner"`

	// PolicyURI is a URL string that points to a human-readable privacy policy document
	// that describes how the deployment organization collects, uses,
	// retains, and discloses personal data.
	PolicyURI string `json:"policy_uri" gorethink:"policy_uri"`

	// TermsOfServiceURI is a URL string that points to a human-readable terms of service
	// document for the client that describes a contractual relationship
	// between the end-user and the client that the end-user accepts when
	// authorizing the client.
	TermsOfServiceURI string `json:"tos_uri" gorethink:"tos_uri"`

	// ClientURI is an URL string of a web page providing information about the client.
	// If present, the server SHOULD display this URL to the end-user in
	// a clickable fashion.
	ClientURI string `json:"client_uri" gorethink:"client_uri"`

	// LogoURI is an URL string that references a logo for the client.
	LogoURI string `json:"logo_uri" gorethink:"logo_uri"`

	// Contacts is a array of strings representing ways to contact people responsible
	// for this client, typically email addresses.
	Contacts []string `json:"contacts" gorethink:"contacts"`

	// Public is a boolean that identifies this client as public, meaning that it
	// does not have a secret. It will disable the client_credentials grant type for this client if set.
	Public bool `json:"public" gorethink:"public"`
}

Client represents an OAuth 2.0 Client.

swagger:model oauthClient

func (*Client) GetGrantTypes

func (c *Client) GetGrantTypes() fosite.Arguments

func (*Client) GetHashedSecret

func (c *Client) GetHashedSecret() []byte

func (*Client) GetID

func (c *Client) GetID() string

func (*Client) GetOwner

func (c *Client) GetOwner() string

func (*Client) GetRedirectURIs

func (c *Client) GetRedirectURIs() []string

func (*Client) GetResponseTypes

func (c *Client) GetResponseTypes() fosite.Arguments

func (*Client) GetScopes

func (c *Client) GetScopes() fosite.Arguments

func (*Client) IsPublic added in v0.6.0

func (c *Client) IsPublic() bool

type HTTPManager

type HTTPManager struct {
	Client             *http.Client
	Endpoint           *url.URL
	Dry                bool
	FakeTLSTermination bool
}

func (*HTTPManager) CreateClient

func (m *HTTPManager) CreateClient(c *Client) error

func (*HTTPManager) DeleteClient

func (m *HTTPManager) DeleteClient(id string) error

func (*HTTPManager) GetClient

func (m *HTTPManager) GetClient(_ context.Context, id string) (fosite.Client, error)

func (*HTTPManager) GetClients

func (m *HTTPManager) GetClients() (map[string]Client, error)

func (*HTTPManager) GetConcreteClient

func (m *HTTPManager) GetConcreteClient(id string) (*Client, error)

func (*HTTPManager) UpdateClient added in v0.5.0

func (m *HTTPManager) UpdateClient(c *Client) error

type Handler

type Handler struct {
	Manager Manager
	H       herodot.Writer
	W       firewall.Firewall
}

func (*Handler) Create

func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

swagger:route POST /clients oauth2 clients createOAuthClient

Creates an OAuth 2.0 Client

Be aware that an OAuth 2.0 Client may gain highly priviledged access if configured that way. This endpoint should be well protected and only called by code you trust.

The subject making the request needs to be assigned to a policy containing:

```
{
  "resources": ["rn:hydra:clients"],
  "actions": ["create"],
  "effect": "allow"
}
```

Additionally, the context key "owner" is set to the owner of the client, allowing policies such as:

```
{
  "resources": ["rn:hydra:clients"],
  "actions": ["create"],
  "effect": "allow",
  "conditions": { "owner": { "type": "EqualsSubjectCondition" } }
}
```

   Consumes:
   - application/json

   Produces:
   - application/json

   Schemes: http, https

   Security:
     oauth2: hydra.clients

   Responses:
     200: oauthClient
     401: genericError
     403: genericError
     500: genericError

func (*Handler) Delete

func (h *Handler) Delete(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

swagger:route DELETE /clients/{id} oauth2 clients deleteOAuthClient

Deletes an OAuth 2.0 Client

The subject making the request needs to be assigned to a policy containing:

```
{
  "resources": ["rn:hydra:clients:<some-id>"],
  "actions": ["delete"],
  "effect": "allow"
}
```

Additionally, the context key "owner" is set to the owner of the client, allowing policies such as:

```
{
  "resources": ["rn:hydra:clients:<some-id>"],
  "actions": ["delete"],
  "effect": "allow",
  "conditions": { "owner": { "type": "EqualsSubjectCondition" } }
}
```

   Consumes:
   - application/json

   Produces:
   - application/json

   Schemes: http, https

   Security:
     oauth2: hydra.clients

   Responses:
     204: emptyResponse
     401: genericError
     403: genericError
     500: genericError

func (*Handler) Get

swagger:route GET /clients/{id} oauth2 clients getOAuthClient

Fetches an OAuth 2.0 Client.

Never returns the client's secret.

The subject making the request needs to be assigned to a policy containing:

```
{
  "resources": ["rn:hydra:clients:<some-id>"],
  "actions": ["get"],
  "effect": "allow"
}
```

Additionally, the context key "owner" is set to the owner of the client, allowing policies such as:

```
{
  "resources": ["rn:hydra:clients:<some-id> "],
  "actions": ["get"],
  "effect": "allow",
  "conditions": { "owner": { "type": "EqualsSubjectCondition" } }
}
```

   Consumes:
   - application/json

   Produces:
   - application/json

   Schemes: http, https

   Security:
     oauth2: hydra.clients

   Responses:
     200: oauthClient
     401: genericError
     403: genericError
     500: genericError

func (*Handler) List added in v0.8.0

swagger:route GET /clients oauth2 clients listOAuthClients

Lists OAuth 2.0 Clients

Never returns a client's secret.

The subject making the request needs to be assigned to a policy containing:

```

{
  "resources": ["rn:hydra:clients"],
  "actions": ["get"],
  "effect": "allow"
}

```

Consumes:
- application/json

Produces:
- application/json

Schemes: http, https

Security:
  oauth2: hydra.clients

Responses:
  200: clientsList
  401: genericError
  403: genericError
  500: genericError

func (*Handler) SetRoutes

func (h *Handler) SetRoutes(r *httprouter.Router)

func (*Handler) Update added in v0.5.0

func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

swagger:route PUT /clients/{id} oauth2 clients updateOAuthClient

Updates an OAuth 2.0 Client

Be aware that an OAuth 2.0 Client may gain highly priviledged access if configured that way. This endpoint should be well protected and only called by code you trust.

The subject making the request needs to be assigned to a policy containing:

```
{
  "resources": ["rn:hydra:clients"],
  "actions": ["update"],
  "effect": "allow"
}
```

Additionally, the context key "owner" is set to the owner of the client, allowing policies such as:

```
{
  "resources": ["rn:hydra:clients"],
  "actions": ["update"],
  "effect": "allow",
  "conditions": { "owner": { "type": "EqualsSubjectCondition" } }
}
```

   Consumes:
   - application/json

   Produces:
   - application/json

   Schemes: http, https

   Security:
     oauth2: hydra.clients

   Responses:
     200: oauthClient
     401: genericError
     403: genericError
     500: genericError

type Manager

type Manager interface {
	Storage

	Authenticate(id string, secret []byte) (*Client, error)
}

type MemoryManager

type MemoryManager struct {
	Clients map[string]Client
	Hasher  fosite.Hasher
	sync.RWMutex
}

func (*MemoryManager) Authenticate

func (m *MemoryManager) Authenticate(id string, secret []byte) (*Client, error)

func (*MemoryManager) CreateClient

func (m *MemoryManager) CreateClient(c *Client) error

func (*MemoryManager) DeleteClient

func (m *MemoryManager) DeleteClient(id string) error

func (*MemoryManager) GetClient

func (m *MemoryManager) GetClient(_ context.Context, id string) (fosite.Client, error)

func (*MemoryManager) GetClients

func (m *MemoryManager) GetClients() (clients map[string]Client, err error)

func (*MemoryManager) GetConcreteClient

func (m *MemoryManager) GetConcreteClient(id string) (*Client, error)

func (*MemoryManager) UpdateClient added in v0.5.0

func (m *MemoryManager) UpdateClient(c *Client) error

type SQLManager added in v0.6.0

type SQLManager struct {
	Hasher fosite.Hasher
	DB     *sqlx.DB
}

func (*SQLManager) Authenticate added in v0.6.0

func (m *SQLManager) Authenticate(id string, secret []byte) (*Client, error)

func (*SQLManager) CreateClient added in v0.6.0

func (m *SQLManager) CreateClient(c *Client) error

func (*SQLManager) CreateSchemas added in v0.6.0

func (s *SQLManager) CreateSchemas() (int, error)

func (*SQLManager) DeleteClient added in v0.6.0

func (m *SQLManager) DeleteClient(id string) error

func (*SQLManager) GetClient added in v0.6.0

func (m *SQLManager) GetClient(_ context.Context, id string) (fosite.Client, error)

func (*SQLManager) GetClients added in v0.6.0

func (m *SQLManager) GetClients() (clients map[string]Client, err error)

func (*SQLManager) GetConcreteClient added in v0.6.0

func (m *SQLManager) GetConcreteClient(id string) (*Client, error)

func (*SQLManager) UpdateClient added in v0.6.0

func (m *SQLManager) UpdateClient(c *Client) error

type Storage

type Storage interface {
	fosite.Storage

	CreateClient(c *Client) error

	UpdateClient(c *Client) error

	DeleteClient(id string) error

	GetClients() (map[string]Client, error)

	GetConcreteClient(id string) (*Client, error)
}

Jump to

Keyboard shortcuts

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