Documentation ¶
Overview ¶
Package client implements the OAuth 2.0 Client functionality and provides http handlers, http clients and storage adapters.
Index ¶
- Constants
- func TestHelperClientAuthenticate(k string, m Manager) func(t *testing.T)
- func TestHelperClientAutoGenerateKey(k string, m Storage) func(t *testing.T)
- func TestHelperCreateGetDeleteClient(k string, m Storage) func(t *testing.T)
- type Client
- func (c *Client) GetGrantTypes() fosite.Arguments
- func (c *Client) GetHashedSecret() []byte
- func (c *Client) GetID() string
- func (c *Client) GetOwner() string
- func (c *Client) GetRedirectURIs() []string
- func (c *Client) GetResponseTypes() fosite.Arguments
- func (c *Client) GetScopes() fosite.Arguments
- func (c *Client) IsPublic() bool
- type HTTPManager
- func (m *HTTPManager) CreateClient(c *Client) error
- func (m *HTTPManager) DeleteClient(id string) error
- func (m *HTTPManager) GetClient(_ context.Context, id string) (fosite.Client, error)
- func (m *HTTPManager) GetClients() (map[string]Client, error)
- func (m *HTTPManager) GetConcreteClient(id string) (*Client, error)
- func (m *HTTPManager) UpdateClient(c *Client) error
- type Handler
- func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
- func (h *Handler) Delete(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- func (h *Handler) Get(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- func (h *Handler) List(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- func (h *Handler) SetRoutes(r *httprouter.Router)
- func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- type Manager
- type MemoryManager
- func (m *MemoryManager) Authenticate(id string, secret []byte) (*Client, error)
- func (m *MemoryManager) CreateClient(c *Client) error
- func (m *MemoryManager) DeleteClient(id string) error
- func (m *MemoryManager) GetClient(_ context.Context, id string) (fosite.Client, error)
- func (m *MemoryManager) GetClients() (clients map[string]Client, err error)
- func (m *MemoryManager) GetConcreteClient(id string) (*Client, error)
- func (m *MemoryManager) UpdateClient(c *Client) error
- type SQLManager
- func (m *SQLManager) Authenticate(id string, secret []byte) (*Client, error)
- func (m *SQLManager) CreateClient(c *Client) error
- func (s *SQLManager) CreateSchemas() (int, error)
- func (m *SQLManager) DeleteClient(id string) error
- func (m *SQLManager) GetClient(_ context.Context, id string) (fosite.Client, error)
- func (m *SQLManager) GetClients() (clients map[string]Client, err error)
- func (m *SQLManager) GetConcreteClient(id string) (*Client, error)
- func (m *SQLManager) UpdateClient(c *Client) error
- type Storage
Constants ¶
const ( ClientsResource = "rn:hydra:clients" ClientResource = "rn:hydra:clients:%s" Scope = "hydra.clients" )
const (
ClientsHandlerPath = "/clients"
)
Variables ¶
This section is empty.
Functions ¶
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 (*Client) GetHashedSecret ¶
func (*Client) GetRedirectURIs ¶
func (*Client) GetResponseTypes ¶
type HTTPManager ¶ added in v0.2.0
func (*HTTPManager) CreateClient ¶ added in v0.2.0
func (m *HTTPManager) CreateClient(c *Client) error
func (*HTTPManager) DeleteClient ¶ added in v0.2.0
func (m *HTTPManager) DeleteClient(id string) error
func (*HTTPManager) GetClients ¶ added in v0.2.0
func (m *HTTPManager) GetClients() (map[string]Client, error)
func (*HTTPManager) GetConcreteClient ¶ added in v0.2.0
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 ¶
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 ¶
func (h *Handler) Get(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
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 ¶
func (h *Handler) List(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
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 ¶
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 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) 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 ¶
func (m *MemoryManager) UpdateClient(c *Client) error
type SQLManager ¶
func (*SQLManager) Authenticate ¶
func (m *SQLManager) Authenticate(id string, secret []byte) (*Client, error)
func (*SQLManager) CreateClient ¶
func (m *SQLManager) CreateClient(c *Client) error
func (*SQLManager) CreateSchemas ¶
func (s *SQLManager) CreateSchemas() (int, error)
func (*SQLManager) DeleteClient ¶
func (m *SQLManager) DeleteClient(id string) error
func (*SQLManager) GetClients ¶
func (m *SQLManager) GetClients() (clients map[string]Client, err error)
func (*SQLManager) GetConcreteClient ¶
func (m *SQLManager) GetConcreteClient(id string) (*Client, error)
func (*SQLManager) UpdateClient ¶
func (m *SQLManager) UpdateClient(c *Client) error