Skip to content

Commit

Permalink
🔥 0.2.0 (ory#165)
Browse files Browse the repository at this point in the history
* warden: rename `assertion` to `token` - closes ory#158
* config: do not log database credentials - closes ory#147
* oauth2: upgrade fosite - close ory#160
* config: do not store database config in hydra config - closes ory#164
* oauth2: id_token at_hash / c_hash is null - closes ory#129
* jwk: improve error message of wrong system secrect - closes ory#104
* readme: improve images, add benchmarks - closes ory#161
* cmd: improve connect dialogue - closes ory#170
* cmd: fix --dry option - closes ory#157
* firewall: document warden interface sdk
* readme: link openid connect and oauth2 introduction
* cmd: introduce FORCE_ROOT_CLIENT_CREDENTIALS env var - closes ory#140
* readme: document error redirect to identity provider - closes ory#96
* internal: fosite store must be consistent to avoid errors - closes ory#176
* client: add GetConcreteClient to http manager
* cmd: host process now logs basic information on all http requests - closes ory#178
* all: add memory profiling - closes ory#179
* warden: resolve nil pointer issue - closes ory#181
* cmd: clean up env to struct mapping, add more controls
* cmd: bcrypt cost should be configurable - closes ory#184
* cmd: token lifespans should be configurable - closes ory#183
* cmd: resolve issues with envirnoment config - closes ory#182
* cmd: implement tls termination capability - closes ory#177
* cmd: resolve issues with redirect logic and TLS
* oauth2: implement default oauth2 consent endpoint - closes ory#185
* warden - closes ory#188 
* oauth2: id token claims should be set by using id_token - closes ory#188
* oauth2: oauth2 implicit flow should allow custom protocols - closes ory#180
* oauth2: core scope should not be mandatory - closes ory#189
* warden: warden sdk should not make distinction between token and request - closes ory#190
* warden: rename authorized / allowed endpoints to something more meaningful - closes ory#162
* ci: improve travis config
  • Loading branch information
arekkas authored Aug 9, 2016
1 parent e62e385 commit a297f7e
Show file tree
Hide file tree
Showing 69 changed files with 1,724 additions and 1,315 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ go:
- 1.6

install:
- go get github.com/axw/gocov/gocov github.com/mattn/goveralls golang.org/x/tools/cmd/cover github.com/pierrre/gotestcover
# Workaround for travis
- go get -t -v ./...
- go install github.com/ory-am/hydra
- go get github.com/mattn/goveralls golang.org/x/tools/cmd/cover github.com/pierrre/gotestcover github.com/Masterminds/glide
- git clone https://github.com/docker-library/official-images.git ~/official-images
- glide install
- go install github.com/ory-am/hydra

script:
- go test -bench=.* -run=nothing $(go list ./... | grep -v /vendor)
- gotestcover -coverprofile="cover.out" $(glide novendor)
- go test -race $(go list ./... | grep -v /vendor | grep -v /cmd)
- gotestcover -coverprofile="cover.out" $(go list ./... | grep -v /vendor/)
- go test -v -bench=.* -run=none $(glide novendor)
- goveralls -coverprofile="cover.out"
- docker build -t hydra-travis-ci .
- docker run -d hydra-travis-ci
Expand Down
408 changes: 200 additions & 208 deletions README.md

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package client

import "github.com/ory-am/fosite"
import (
"github.com/ory-am/fosite"
"strings"
)

type Client struct {
ID string `json:"id" gorethink:"id"`
Expand All @@ -9,7 +12,7 @@ type Client struct {
RedirectURIs []string `json:"redirect_uris" gorethink:"redirect_uris"`
GrantTypes []string `json:"grant_types" gorethink:"grant_types"`
ResponseTypes []string `json:"response_types" gorethink:"response_types"`
GrantedScopes []string `json:"granted_scopes" gorethink:"granted_scopes"`
Scopes string `json:"scopes" gorethink:"scopes"`
Owner string `json:"owner" gorethink:"owner"`
PolicyURI string `json:"policy_uri" gorethink:"policy_uri"`
TermsOfServiceURI string `json:"tos_uri" gorethink:"tos_uri"`
Expand All @@ -30,10 +33,8 @@ func (c *Client) GetHashedSecret() []byte {
return []byte(c.Secret)
}

func (c *Client) GetGrantedScopes() fosite.Scopes {
return &fosite.DefaultScopes{
Scopes: c.GrantedScopes,
}
func (c *Client) GetScopes() fosite.Arguments {
return fosite.Arguments(strings.Split(c.Scopes, " "))
}

func (c *Client) GetGrantTypes() fosite.Arguments {
Expand Down
12 changes: 6 additions & 6 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
return
}

if _, err := h.W.HTTPActionAllowed(ctx, r, &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
Resource: ClientsResource,
Action: "create",
Context: ladon.Context{
Expand Down Expand Up @@ -80,7 +80,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
func (h *Handler) GetAll(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var ctx = herodot.NewContext()

if _, err := h.W.HTTPActionAllowed(ctx, r, &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
Resource: ClientsResource,
Action: "get",
}, Scope); err != nil {
Expand All @@ -106,13 +106,13 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request, ps httprouter.Para
var ctx = herodot.NewContext()
var id = ps.ByName("id")

c, err := h.Manager.GetClient(id)
c, err := h.Manager.GetConcreteClient(id)
if err != nil {
h.H.WriteError(ctx, w, r, err)
return
}

if _, err := h.W.HTTPActionAllowed(ctx, r, &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
Resource: fmt.Sprintf(ClientResource, id),
Action: "get",
Context: ladon.Context{
Expand All @@ -123,15 +123,15 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request, ps httprouter.Para
return
}

c.(*Client).Secret = ""
c.Secret = ""
h.H.Write(ctx, w, r, c)
}

func (h *Handler) Delete(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var ctx = herodot.NewContext()
var id = ps.ByName("id")

if _, err := h.W.HTTPActionAllowed(ctx, r, &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
Resource: fmt.Sprintf(ClientResource, id),
Action: "delete",
}, Scope); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions client/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ type Storage interface {
DeleteClient(id string) error

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

GetConcreteClient(id string) (*Client, error)
}
6 changes: 5 additions & 1 deletion client/manager_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type HTTPManager struct {
Dry bool
}

func (m *HTTPManager) GetClient(id string) (fosite.Client, error) {
func (m *HTTPManager) GetConcreteClient(id string) (*Client, error) {
var c Client
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, id).String())
r.Client = m.Client
Expand All @@ -26,6 +26,10 @@ func (m *HTTPManager) GetClient(id string) (fosite.Client, error) {
return &c, nil
}

func (m *HTTPManager) GetClient(id string) (fosite.Client, error) {
return m.GetConcreteClient(id)
}

func (m *HTTPManager) CreateClient(c *Client) error {
var r = pkg.NewSuperAgent(m.Endpoint.String())
r.Client = m.Client
Expand Down
6 changes: 5 additions & 1 deletion client/manager_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type MemoryManager struct {
sync.RWMutex
}

func (m *MemoryManager) GetClient(id string) (fosite.Client, error) {
func (m *MemoryManager) GetConcreteClient(id string) (*Client, error) {
m.RLock()
defer m.RUnlock()

Expand All @@ -27,6 +27,10 @@ func (m *MemoryManager) GetClient(id string) (fosite.Client, error) {
return &c, nil
}

func (m *MemoryManager) GetClient(id string) (fosite.Client, error) {
return m.GetConcreteClient(id)
}

func (m *MemoryManager) Authenticate(id string, secret []byte) (*Client, error) {
m.RLock()
defer m.RUnlock()
Expand Down
6 changes: 5 additions & 1 deletion client/manager_rethinkdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type RethinkManager struct {
Hasher hash.Hasher
}

func (m *RethinkManager) GetClient(id string) (fosite.Client, error) {
func (m *RethinkManager) GetConcreteClient(id string) (*Client, error) {
m.RLock()
defer m.RUnlock()

Expand All @@ -34,6 +34,10 @@ func (m *RethinkManager) GetClient(id string) (fosite.Client, error) {
return &c, nil
}

func (m *RethinkManager) GetClient(id string) (fosite.Client, error) {
return m.GetConcreteClient(id)
}

func (m *RethinkManager) Authenticate(id string, secret []byte) (*Client, error) {
m.RLock()
defer m.RUnlock()
Expand Down
2 changes: 1 addition & 1 deletion client/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/julienschmidt/httprouter"
"github.com/ory-am/dockertest"
"github.com/ory-am/fosite"
"github.com/ory-am/fosite/hash"
. "github.com/ory-am/hydra/client"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
"gopkg.in/ory-am/dockertest.v2"
)

var clientManagers = map[string]Storage{}
Expand Down
7 changes: 3 additions & 4 deletions cmd/cli/handler_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ory-am/hydra/config"
"github.com/ory-am/hydra/pkg"
"github.com/spf13/cobra"
"strings"
)

type ClientHandler struct {
Expand All @@ -24,7 +25,6 @@ func newClientHandler(c *config.Config) *ClientHandler {
}

func (h *ClientHandler) ImportClients(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Endpoint = h.Config.Resolve("/clients")
h.M.Client = h.Config.OAuth2Client(cmd)
if len(args) == 0 {
Expand Down Expand Up @@ -52,7 +52,7 @@ func (h *ClientHandler) ImportClients(cmd *cobra.Command, args []string) {
func (h *ClientHandler) CreateClient(cmd *cobra.Command, args []string) {
var err error

h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/clients")
h.M.Client = h.Config.OAuth2Client(cmd)

Expand All @@ -70,7 +70,7 @@ func (h *ClientHandler) CreateClient(cmd *cobra.Command, args []string) {
ID: id,
Secret: string(secret),
ResponseTypes: responseTypes,
GrantedScopes: allowedScopes,
Scopes: strings.Join(allowedScopes, " "),
GrantTypes: grantTypes,
RedirectURIs: callbacks,
Name: name,
Expand All @@ -87,7 +87,6 @@ func (h *ClientHandler) CreateClient(cmd *cobra.Command, args []string) {
}

func (h *ClientHandler) DeleteClient(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Endpoint = h.Config.Resolve("/clients")
h.M.Client = h.Config.OAuth2Client(cmd)
if len(args) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/handler_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newConnectionHandler(c *config.Config) *ConnectionHandler {
}

func (h *ConnectionHandler) CreateConnection(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Client = h.Config.OAuth2Client(cmd)
h.M.Endpoint = h.Config.Resolve("/connections")
if len(args) != 3 {
Expand All @@ -45,7 +45,7 @@ func (h *ConnectionHandler) CreateConnection(cmd *cobra.Command, args []string)
}

func (h *ConnectionHandler) DeleteConnection(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Client = h.Config.OAuth2Client(cmd)
h.M.Endpoint = h.Config.Resolve("/connections")
if len(args) == 0 {
Expand Down
5 changes: 3 additions & 2 deletions cmd/cli/handler_jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newJWKHandler(c *config.Config) *JWKHandler {
}

func (h *JWKHandler) CreateKeys(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/keys")
h.M.Client = h.Config.OAuth2Client(cmd)
if len(args) == 0 {
Expand All @@ -46,7 +46,7 @@ func (h *JWKHandler) CreateKeys(cmd *cobra.Command, args []string) {
}

func (h *JWKHandler) GetKeys(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/keys")
h.M.Client = h.Config.OAuth2Client(cmd)
if len(args) == 0 {
Expand All @@ -68,6 +68,7 @@ func (h *JWKHandler) GetKeys(cmd *cobra.Command, args []string) {
}

func (h *JWKHandler) DeleteKeys(cmd *cobra.Command, args []string) {
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/keys")
h.M.Client = h.Config.OAuth2Client(cmd)
if len(args) == 0 {
Expand Down
15 changes: 6 additions & 9 deletions cmd/cli/handler_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newPolicyHandler(c *config.Config) *PolicyHandler {
}

func (h *PolicyHandler) CreatePolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/policies")
h.M.Client = h.Config.OAuth2Client(cmd)

Expand Down Expand Up @@ -80,7 +80,7 @@ func (h *PolicyHandler) CreatePolicy(cmd *cobra.Command, args []string) {
}

func (h *PolicyHandler) AddResourceToPolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/policies")
h.M.Client = h.Config.OAuth2Client(cmd)

Expand Down Expand Up @@ -112,12 +112,11 @@ func (h *PolicyHandler) AddResourceToPolicy(cmd *cobra.Command, args []string) {
}

func (h *PolicyHandler) RemoveResourceFromPolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
fmt.Println("Not yet implemented.")
}

func (h *PolicyHandler) AddSubjectToPolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/policies")
h.M.Client = h.Config.OAuth2Client(cmd)

Expand Down Expand Up @@ -149,12 +148,11 @@ func (h *PolicyHandler) AddSubjectToPolicy(cmd *cobra.Command, args []string) {
}

func (h *PolicyHandler) RemoveSubjectFromPolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
fmt.Println("Not yet implemented.")
}

func (h *PolicyHandler) AddActionToPolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/policies")
h.M.Client = h.Config.OAuth2Client(cmd)

Expand Down Expand Up @@ -186,12 +184,11 @@ func (h *PolicyHandler) AddActionToPolicy(cmd *cobra.Command, args []string) {
}

func (h *PolicyHandler) RemoveActionFromPolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
fmt.Println("Not yet implemented.")
}

func (h *PolicyHandler) GetPolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/policies")
h.M.Client = h.Config.OAuth2Client(cmd)

Expand All @@ -214,7 +211,7 @@ func (h *PolicyHandler) GetPolicy(cmd *cobra.Command, args []string) {
}

func (h *PolicyHandler) DeletePolicy(cmd *cobra.Command, args []string) {
h.M.Dry = *h.Config.Dry
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/policies")
h.M.Client = h.Config.OAuth2Client(cmd)

Expand Down
7 changes: 2 additions & 5 deletions cmd/cli/handler_warden.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func newWardenHandler(c *config.Config) *WardenHandler {
}

func (h *WardenHandler) IsAuthorized(cmd *cobra.Command, args []string) {
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Client = h.Config.OAuth2Client(cmd)
h.M.Endpoint = h.Config.Resolve("/connections")

Expand All @@ -33,11 +34,7 @@ func (h *WardenHandler) IsAuthorized(cmd *cobra.Command, args []string) {
}

scopes, _ := cmd.Flags().GetStringSlice("scopes")
if len(scopes) == 0 {
scopes = []string{"core"}
}

res, err := h.M.Authorized(context.Background(), args[0], scopes...)
res, err := h.M.InspectToken(context.Background(), args[0], scopes...)
pkg.Must(err, "Could not validate token: %s", err)

out, err := json.MarshalIndent(res, "", "\t")
Expand Down
6 changes: 1 addition & 5 deletions cmd/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ var clientsCmd = &cobra.Command{
}

func init() {
var dry bool
c.Dry = &dry

RootCmd.AddCommand(clientsCmd)
clientsCmd.PersistentFlags().Bool("dry", false, "do not execute the command but show the corresponding curl command instead")

clientsCmd.PersistentFlags().BoolVar(c.Dry, "dry", false, "do not execute the command but show the corresponding curl command instead")
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand All @@ -41,5 +38,4 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// clientsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

}
2 changes: 1 addition & 1 deletion cmd/clients_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ func init() {
clientsCreateCmd.Flags().StringSliceP("callbacks", "c", []string{}, "REQUIRED list of allowed callback URLs")
clientsCreateCmd.Flags().StringSliceP("grant-types", "g", []string{"authorization_code"}, "A list of allowed grant types")
clientsCreateCmd.Flags().StringSliceP("response-types", "r", []string{"code"}, "A list of allowed response types")
clientsCreateCmd.Flags().StringSliceP("allowed-scopes", "a", []string{"core"}, "A list of allowed scopes")
clientsCreateCmd.Flags().StringSliceP("allowed-scopes", "a", []string{""}, "A list of allowed scopes")
clientsCreateCmd.Flags().StringP("name", "n", "", "The client's name")
}
Loading

0 comments on commit a297f7e

Please sign in to comment.