From 139f12193abaf621b0c253db3dc0494dc0560267 Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Mon, 12 Jun 2017 23:42:16 +0200 Subject: [PATCH] Added context, updated to Hydra 0.9.x --- glide.lock | 79 +++++++++++++++++++++++++++++------------------------- glide.yaml | 2 +- idp.go | 9 ++++--- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/glide.lock b/glide.lock index 0aca22b..207be07 100644 --- a/glide.lock +++ b/glide.lock @@ -1,8 +1,8 @@ -hash: c06e7fbb7e614489e9ec74a0684af671fa6f34f034fb2e50d7de6d8ff818e971 -updated: 2017-06-02T23:59:32.103139052+02:00 +hash: a3f328958524ac984b6d6bf9156d615880c25b7f27fabe19ea78a60f6c052c66 +updated: 2017-06-12T23:33:35.072968004+02:00 imports: - name: github.com/asaskevich/govalidator - version: 7b3beb6df3c42abd3509abfc3bcacc0fbfb7c877 + version: 4918b99a7cb949bb295f3c7bbaf24b577d806e35 - name: github.com/davecgh/go-spew version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: @@ -10,19 +10,17 @@ imports: - name: github.com/dgrijalva/jwt-go version: d2709f9f1f31ebcda9651b03077758c1f3a0018c - name: github.com/fsnotify/fsnotify - version: a904159b9206978bb6d53fcc7a769e5cd726c737 -- name: github.com/go-errors/errors - version: 8fa88b06e5974e97fbf9899a7f86a344bfd1f105 + version: 4da3e2cfbabc9f751898f250b49f2439785783a1 - name: github.com/go-sql-driver/mysql version: a0583e0143b1624142adab07e0e97fe106d99561 - name: github.com/golang/protobuf - version: 1f49d83d9aa00e6ce4fc8258c71cc7786aec968a + version: 2402d76f3d41f928c7902a765dfc872356dd3aad subpackages: - proto - name: github.com/gorilla/context version: 1ea25387ff6f684839d82767c1733ff4d4d15d0a - name: github.com/gorilla/securecookie - version: fa5329f913702981df43dcb2a380bac429c810b5 + version: e59506cc896acb7f7bf732d4fdf5e25f7ccd8983 - name: github.com/gorilla/sessions version: ca9ada44574153444b00d3fd9c8559e4cc95f896 - name: github.com/hashicorp/golang-lru @@ -30,7 +28,7 @@ imports: subpackages: - simplelru - name: github.com/hashicorp/hcl - version: 372e8ddaa16fd67e371e9323807d056b799360af + version: 392dba7d905ed5d04a5794ba89f558b27e2ba1ca subpackages: - hcl/ast - hcl/parser @@ -44,32 +42,28 @@ imports: version: 3e95a51e0639b4cf372f2ccf74c86749d747fbdc - name: github.com/inconshreveable/mousetrap version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 +- name: github.com/jehiah/go-strftime + version: 834e15c05a45371503440cc195bbd05c9a0968d9 - name: github.com/jmoiron/sqlx - version: f980a91bdc37abef88269b8f122d7de6352102f5 + version: d9bd385d68c068f1fabb5057e3dedcbcbb039d0f subpackages: - reflectx - name: github.com/julienschmidt/httprouter version: 8c199fb6259ffc1af525cc3ad52ee60ba8359669 - name: github.com/lib/pq - version: d67b1982b9d913b680e5f04323785fc69366d306 + version: 8837942c3e09574accbc5f150e2c5e057189cace subpackages: - oid - name: github.com/magiconair/properties - version: b3b15ef068fd0b17ddf408a23669f20811d194d2 + version: 51463bfca2576e06c62a8504b5c0f06d61312647 - name: github.com/mitchellh/mapstructure - version: db1efb556f84b25a0a13a04aad883943538ad2e0 + version: d0303fe809921458f417bcf828397a65db30a7e4 - name: github.com/moul/http2curl version: 4e24498b31dba4683efb9d35c1c8a91e2eda28c8 - name: github.com/oleiade/reflections version: 2b6ec3da648e3e834dc41bad8d9ed7f2dc6a9496 -- name: github.com/ory-am/common - version: b6357395e30805e2ad1f6d8fb759fa2b7146d8da - subpackages: - - compiler - - pkg - - rand/sequence - name: github.com/ory/fosite - version: 575dd791f9f11cd8e5471178b1ec3a7638653cae + version: 82944aaa42ddc9c718ee072d5a11635ec982394d subpackages: - compose - handler/oauth2 @@ -80,22 +74,25 @@ imports: - name: github.com/ory/herodot version: ef15ccfb8c16051feca9ec289286732f8d288fec - name: github.com/ory/hydra - version: baf60d29d99aae9b5100181374b150075796342f + version: a04e6f2f1b2f748e0ed762375ec65204a326dd7b subpackages: - client - config - firewall - jwk + - metrics - oauth2 - pkg - pkg/helper - policy + - rand/sequence - sdk - warden - warden/group - name: github.com/ory/ladon - version: 24fe723368e1f47534219523c0580948cc7b873e + version: c8b0a3309bb2fc36f1dc24035279cc7530af0a0a subpackages: + - compiler - manager/memory - manager/sql - name: github.com/patrickmn/go-cache @@ -103,9 +100,9 @@ imports: - name: github.com/pborman/uuid version: a97ce2ca70fa5a848076093f05e639a89ca34d06 - name: github.com/pelletier/go-buffruneio - version: df1e16fde7fc330a0ca68167c23bf7ed6ac31d6d + version: c37440a7cf42ac63b919c752ca73a85067e05992 - name: github.com/pelletier/go-toml - version: c9506ee96398e7571356462217b9e24d6a628d71 + version: fe7536c3dee2596cdd23ee9976a17c22bdaae286 - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/pmezard/go-difflib @@ -113,25 +110,29 @@ imports: subpackages: - difflib - name: github.com/rubenv/sql-migrate - version: f64b6080c334adaf843209164107439e92bb170b + version: 06556f04fd065acf72dca41b344b1f73a503b9c7 subpackages: - sqlparse +- name: github.com/segmentio/analytics-go + version: bdb0aeca8a993b292b85c9ec17b5ce0ff81848c8 +- name: github.com/segmentio/backo-go + version: 204274ad699c0983a70203a566887f17a717fef4 - name: github.com/Sirupsen/logrus version: ba1b36c82c5e05c4f912a88eab0dcd91a171688f - name: github.com/spf13/afero - version: 72b31426848c6ef12a7a8e216708cb0d1530f074 + version: 9be650865eab0c12963d8753212f4f9c66cdcf12 subpackages: - mem - name: github.com/spf13/cast - version: d1139bab1c07d5ad390a65e7305876b3c1a8370b + version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 - name: github.com/spf13/cobra - version: b5d8e8f46a2f829f755b6e33b454e25c61c935e1 + version: b4dbd37a01839e0653eec12aa4bbb2a2ce7b2a37 - name: github.com/spf13/jwalterweatherman - version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66 + version: 0efa5202c04663c757d84f90f5219c1250baf94f - name: github.com/spf13/pflag - version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 + version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 - name: github.com/spf13/viper - version: 5ed0fc31f7f453625df314d8e66b9791e8d13003 + version: a1ecfa6a20bd4ef9e9caded262ee1b1b26847675 - name: github.com/square/go-jose version: aa2e30fdd1fe9dd3394119af66451ae790d50e0d subpackages: @@ -141,8 +142,12 @@ imports: subpackages: - assert - require +- name: github.com/urfave/negroni + version: fde5e16d32adc7ad637e9cd9ad21d4ebc6192535 +- name: github.com/xtgo/uuid + version: a0b114877d4caeffbd7f87e3757c17fce570fea7 - name: golang.org/x/crypto - version: 453249f01cfeb54c3d549ddb75ff152ca243f9d8 + version: e7ba82683099cae71475961448ab8f903ea77c26 subpackages: - bcrypt - blowfish @@ -151,21 +156,21 @@ imports: subpackages: - context - name: golang.org/x/oauth2 - version: de0725b330ab43c1a3d6c84d961cf01183783f1e + version: f047394b6d14284165300fd82dad67edb3a4d7f6 subpackages: - clientcredentials - internal - name: golang.org/x/sys - version: e24f485414aeafb646f6fca458b0bf869c0880a1 + version: 0b25a408a50076fbbcae6b7ac0ea5fbb0b085e79 subpackages: - unix - name: golang.org/x/text - version: 06d6eba81293389cafdff7fca90d75592194b2d9 + version: 210eee5cf7323015d097341bcf7166130d001cd8 subpackages: - transform - unicode/norm - name: google.golang.org/appengine - version: 2e4a801b39fc199db615bfca7d0b9f8cd9580599 + version: a2f4131514e563cedfdb6e7d267df9ad48591e93 subpackages: - internal - internal/base @@ -182,5 +187,5 @@ imports: - cipher - json - name: gopkg.in/yaml.v2 - version: a3f3340b5840cee44f372bddb5880fcbc419b46a + version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b testImports: [] diff --git a/glide.yaml b/glide.yaml index 0da4a38..3e84c5e 100644 --- a/glide.yaml +++ b/glide.yaml @@ -5,7 +5,7 @@ import: - package: github.com/gorilla/sessions version: ~1.1.0 - package: github.com/ory/hydra - version: ~0.8.5 + version: ~0.9.0 subpackages: - client - jwk diff --git a/idp.go b/idp.go index b096269..069ef56 100644 --- a/idp.go +++ b/idp.go @@ -1,6 +1,7 @@ package idp import ( + "context" "crypto/rsa" "net/http" "time" @@ -260,7 +261,7 @@ func (idp *IDP) getVerificationKey() (*rsa.PublicKey, error) { return key, nil } -func (idp *IDP) getClient(clientID string) (*hclient.Client, error) { +func (idp *IDP) getClient(ctx context.Context, clientID string) (*hclient.Client, error) { clientKey := ClientInfoKey(clientID) data, ok := idp.cache.Get(clientKey) if ok { @@ -271,7 +272,7 @@ func (idp *IDP) getClient(clientID string) (*hclient.Client, error) { return nil, ErrorNoSuchClient } - client, err := idp.hc.Clients.GetClient(clientID) + client, err := idp.hc.Clients.GetClient(ctx, clientID) if err != nil { // Either the client isn't registered in hydra, or maybe hydra is // having some problem. Either way, ensure we don't hit hydra again @@ -286,7 +287,7 @@ func (idp *IDP) getClient(clientID string) (*hclient.Client, error) { } // Create a new Challenge. The request will contain all the necessary information from Hydra, passed in the URL. -func (idp *IDP) NewChallenge(r *http.Request, user string) (challenge *Challenge, err error) { +func (idp *IDP) NewChallenge(ctx context.Context, r *http.Request, user string) (challenge *Challenge, err error) { tokenStr := r.FormValue("challenge") if tokenStr == "" { // No challenge token @@ -310,7 +311,7 @@ func (idp *IDP) NewChallenge(r *http.Request, user string) (challenge *Challenge } // Get data from the challenge jwt - challenge.Client, err = idp.getClient(claims["aud"].(string)) + challenge.Client, err = idp.getClient(ctx, claims["aud"].(string)) if err != nil { return nil, err }