Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: switch to swagger codegen sdk #585

Merged
merged 44 commits into from
Sep 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6fb805e
sdk: add node and go SDK from swagger codegen
Sep 26, 2017
89ce9e3
sdk/go: move go sdk to appropriate package
Sep 26, 2017
78b5c84
client: write test for swagger codegen sdk
Sep 26, 2017
9365d28
client: force swagger array type in list response
Sep 26, 2017
189b3eb
client: appropriately handle client secret responses
Sep 26, 2017
17c3b93
client: add memory manager instantiator
Sep 26, 2017
89c8b47
sdk: update swagger definitions and codegens
Sep 26, 2017
440b7fa
client: return array instead of object on list endpoint
Sep 26, 2017
297d9fd
client: finalize SDK tests
Sep 26, 2017
0721043
all: run gofmt
Sep 26, 2017
31bc8b0
client: remove obsolete http manager
Sep 26, 2017
b1169ad
health: disable TLS restriction for health check (#587)
arekkas Sep 26, 2017
dc67402
Merge branch 'master' into prepare-1.0.0-alpha1-sdk
Sep 26, 2017
b390690
sdk/go: switch to resty master for oauth2 compatibility
Sep 27, 2017
125112a
client: clean up sdk tests
Sep 27, 2017
55dea18
cmd/client: use new sdk for client cli
Sep 27, 2017
fb38d8c
scripts: add swagger codegen cli to repo
Sep 27, 2017
28ff2d9
sdk: update swagger definitions
Sep 27, 2017
c900464
all: run gofmt
Sep 27, 2017
339ef6c
all: update swagger definitions
Sep 27, 2017
2b10fb6
jwk: implement swagger-based sdk
Sep 27, 2017
8cd73da
scripts: remove swagger-codegen jar from git
Sep 27, 2017
679a45a
oauth2: improve swagger definitions
Sep 27, 2017
fdcf548
oauth2: improve swagger spec and generate/test client for revoke
Sep 27, 2017
4500d65
client: resolve failing test
Sep 27, 2017
0d22329
scripts: update sdk generator script
Sep 27, 2017
f792d1b
sdk: move sdk one directory down
Sep 27, 2017
d9674c8
all: add hydra to swagger tags
Sep 27, 2017
dab03ff
oauth2: implement swagger-based sdk
Sep 27, 2017
a1f0dba
sdk: allow redirects in resty client
Sep 27, 2017
401b613
all: update swagger definitions and combine in hydra interface
Sep 27, 2017
97f6e0c
policy: implement policy sdk and tests based on swagger
Sep 27, 2017
9466eb7
cmd/cli: fake-tls-termination and refactoring errors checks
Sep 27, 2017
8a9f1ea
cmd/cli: implement policy handler based on swagger client
Sep 27, 2017
e36b994
all: reduce tags to one and clean up sdk
Sep 27, 2017
7f14071
vendor: add go-resty to glide dependencies
Sep 28, 2017
93e5fd3
travis: update swagger location
Sep 28, 2017
be657fd
all: improve swagger documentation of all modules
Sep 28, 2017
da4edcc
warden: implement swagger based SDK and write tests
Sep 28, 2017
452d9b4
oauth2: return consent deny reason to oauth2 initiator
Sep 28, 2017
d0bf6d2
docs: add API version note
Sep 28, 2017
05cf6af
warden/group: refactor group sdk and group management interface
Sep 29, 2017
4bc0fa3
sdk: update sdk definitions
Sep 29, 2017
a27237f
all: update swagger definitions and fix failing tests
Sep 29, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ output/
_book/
dist/
coverage.*
docs/api.swagger.json
Dockerfile-plugin-*
plugin-*.so
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ before_install:
- sudo apt-get install curl

install:
- go get -u github.com/go-swagger/go-swagger github.com/bradfitz/goimports github.com/mattn/goveralls golang.org/x/tools/cmd/cover github.com/Masterminds/glide github.com/mitchellh/gox github.com/ory/go-acc
- go get -u github.com/go-swagger/go-swagger/cmd/swagger github.com/bradfitz/goimports github.com/mattn/goveralls golang.org/x/tools/cmd/cover github.com/Masterminds/glide github.com/mitchellh/gox github.com/ory/go-acc
- git clone https://github.com/docker-library/official-images.git ~/official-images
- glide install
- go install github.com/ory/hydra
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Client represents an OAuth 2.0 Client.
//
// swagger:model oauthClient
// swagger:model oAuth2Client
type Client struct {
// ID is the id for this client.
ID string `json:"id" gorethink:"id"`
Expand Down
18 changes: 13 additions & 5 deletions client/doc.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// Package client implements the OAuth 2.0 Client functionality and provides http handlers, http clients and storage adapters.
// Package client implements OAuth 2.0 client management capabilities
//
// OAuth 2.0 clients are used to perform OAuth 2.0 and OpenID Connect flows. Usually, OAuth 2.0 clients are granted
// to applications that want to use OAuth 2.0 access and refresh tokens.
//
//
// In ORY Hydra, OAuth 2.0 clients are used to manage ORY Hydra itself. These clients may gain highly privileged access
// if configured that way. This endpoint should be well protected and only called by code you trust.
package client

// swagger:parameters createOAuthClient
// swagger:parameters createOAuth2Client
type swaggerCreateClientPayload struct {
// in: body
// required: true
Body Client
}

// swagger:parameters updateOAuthClient
// swagger:parameters updateOAuth2Client
type swaggerUpdateClientPayload struct {
// in: path
// required: true
Expand All @@ -20,13 +27,14 @@ type swaggerUpdateClientPayload struct {
}

// A list of clients.
// swagger:response clientsList
// swagger:response oAuth2ClientList
type swaggerListClientsResult struct {
// in: body
// type: array
Body []Client
}

// swagger:parameters getOAuthClient deleteOAuthClient
// swagger:parameters getOAuth2Client deleteOAuth2Client
type swaggerQueryClientPayload struct {
// The id of the OAuth 2.0 Client.
//
Expand Down
59 changes: 36 additions & 23 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ func (h *Handler) SetRoutes(r *httprouter.Router) {
r.DELETE(ClientsHandlerPath+"/:id", h.Delete)
}

// swagger:route POST /clients oauth2 clients createOAuthClient
// swagger:route POST /clients oAuth2 createOAuth2Client
//
// Creates an OAuth 2.0 Client
// 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.
//
// 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:
//
Expand Down Expand Up @@ -77,7 +79,7 @@ func (h *Handler) SetRoutes(r *httprouter.Router) {
// oauth2: hydra.clients
//
// Responses:
// 200: oauthClient
// 200: oAuth2Client
// 401: genericError
// 403: genericError
// 500: genericError
Expand Down Expand Up @@ -122,12 +124,13 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
h.H.WriteCreated(w, r, ClientsHandlerPath+"/"+c.GetID(), &c)
}

// swagger:route PUT /clients/{id} oauth2 clients updateOAuthClient
// swagger:route PUT /clients/{id} oAuth2 updateOAuth2Client
//
// Update an OAuth 2.0 Client
//
// Updates 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.
//
// 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:
//
Expand Down Expand Up @@ -162,7 +165,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
// oauth2: hydra.clients
//
// Responses:
// 200: oauthClient
// 200: oAuth2Client
// 401: genericError
// 403: genericError
// 500: genericError
Expand Down Expand Up @@ -192,8 +195,12 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.P
return
}

var secret string
if len(c.Secret) > 0 && len(c.Secret) < 6 {
h.H.WriteError(w, r, errors.New("The client secret must be at least 6 characters long"))
return
} else {
secret = c.Secret
}

c.ID = ps.ByName("id")
Expand All @@ -202,14 +209,16 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.P
return
}

c.Secret = secret
h.H.WriteCreated(w, r, ClientsHandlerPath+"/"+c.GetID(), &c)
}

// swagger:route GET /clients oauth2 clients listOAuthClients
// swagger:route GET /clients oAuth2 listOAuth2Clients
//
// Lists OAuth 2.0 Clients
// List OAuth 2.0 Clients
//
// This endpoint never returns passwords.
//
// Never returns a client's secret.
//
// The subject making the request needs to be assigned to a policy containing:
//
Expand All @@ -233,7 +242,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.P
// oauth2: hydra.clients
//
// Responses:
// 200: clientsList
// 200: oAuth2ClientList
// 401: genericError
// 403: genericError
// 500: genericError
Expand All @@ -254,19 +263,23 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request, ps httprouter.Par
return
}

for k, cc := range c {
cc.Secret = ""
c[k] = cc
clients := make([]Client, len(c))
k := 0
for _, cc := range c {
clients[k] = cc
clients[k].Secret = ""
k++
}

h.H.Write(w, r, c)
h.H.Write(w, r, clients)
}

// swagger:route GET /clients/{id} oauth2 clients getOAuthClient
// swagger:route GET /clients/{id} oAuth2 getOAuth2Client
//
// Retrieve an OAuth 2.0 Client.
//
// Fetches an OAuth 2.0 Client.
// This endpoint never returns passwords.
//
// Never returns the client's secret.
//
// The subject making the request needs to be assigned to a policy containing:
//
Expand Down Expand Up @@ -301,7 +314,7 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request, ps httprouter.Par
// oauth2: hydra.clients
//
// Responses:
// 200: oauthClient
// 200: oAuth2Client
// 401: genericError
// 403: genericError
// 500: genericError
Expand Down Expand Up @@ -330,7 +343,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request, ps httprouter.Para
h.H.Write(w, r, c)
}

// swagger:route DELETE /clients/{id} oauth2 clients deleteOAuthClient
// swagger:route DELETE /clients/{id} oAuth2 deleteOAuth2Client
//
// Deletes an OAuth 2.0 Client
//
Expand Down
74 changes: 0 additions & 74 deletions client/manager_http.go

This file was deleted.

14 changes: 12 additions & 2 deletions client/manager_memory.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package client

import (
"sync"

"context"
"sync"

"github.com/imdario/mergo"
"github.com/ory/fosite"
Expand All @@ -18,6 +17,17 @@ type MemoryManager struct {
sync.RWMutex
}

func NewMemoryManager(hasher fosite.Hasher) *MemoryManager {
if hasher == nil {
hasher = new(fosite.BCrypt)
}

return &MemoryManager{
Clients: map[string]Client{},
Hasher: hasher,
}
}

func (m *MemoryManager) GetConcreteClient(id string) (*Client, error) {
m.RLock()
defer m.RUnlock()
Expand Down
Loading