client

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientsResource = "clients"
	ClientResource  = "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 oAuth2Client

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 Handler

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

func (*Handler) Create

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

swagger:route POST /clients oAuth2 createOAuth2Client

Create an OAuth 2.0 client

If you pass `client_secret` the secret will be used, otherwise a random secret will be generated. The secret will be returned in the response and you will not be able to retrieve it later on. Write the secret down and keep it somwhere safe.

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: oAuth2Client
     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 deleteOAuth2Client

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 getOAuth2Client

Retrieve an OAuth 2.0 Client.

This endpoint never returns passwords.

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: oAuth2Client
     401: genericError
     403: genericError
     500: genericError

func (*Handler) List added in v0.8.0

swagger:route GET /clients oAuth2 listOAuth2Clients

List OAuth 2.0 Clients

This endpoint never returns passwords.

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: oAuth2ClientList
  401: genericError
  403: genericError
  500: genericError

func (*Handler) PrefixResource added in v0.10.0

func (h *Handler) PrefixResource(resource string) string

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 updateOAuth2Client

Update an OAuth 2.0 Client

If you pass `client_secret` the secret will be updated and returned via the API. This is the only time you will be able to retrieve the client secret, so write it down and keep it safe.

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: oAuth2Client
     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 NewMemoryManager added in v0.9.14

func NewMemoryManager(hasher fosite.Hasher) *MemoryManager

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