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

IDM-197 Implement JWT bearer token flow in Hydra #1

Merged
merged 4 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ Then run it with in-memory database:
DATABASE_URL=memory go run main.go host
```

If you want to add mocks for the interfaces you are being testing, refer to [generator script](generate-mocks.sh).
* Add needed mocks generation to this script.
* Then run
```bash
go get github.com/golang/mock/gomock # if you don't have it
go get github.com/golang/mock/mockgen # if you don't have it
go get golang.org/x/tools/cmd/goimports # if you don't have it
./generate-mocks.sh
```

**Notes**

* We changed organization name from `ory-am` to `ory`. In order to keep backwards compatibility, we did not rename Go packages.
Expand Down
8 changes: 7 additions & 1 deletion cmd/server/handler_oauth2_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func injectFositeStore(c *config.Config, clients client.Manager) {

func newOAuth2Provider(c *config.Config, km jwk.Manager) fosite.OAuth2Provider {
var ctx = c.Context()
var store = ctx.FositeStore
var store = oauth2.CommonStore{
FositeStorer: ctx.FositeStore,
KeyManager: km,
ClusterURL: c.ClusterURL,
}

createRS256KeysIfNotExist(c, oauth2.OpenIDConnectKeyName, "private", "sig")
keys, err := km.GetKey(oauth2.OpenIDConnectKeyName, "private")
Expand All @@ -80,6 +84,7 @@ func newOAuth2Provider(c *config.Config, km jwk.Manager) fosite.OAuth2Provider {
IDTokenLifespan: c.GetIDTokenLifespan(),
HashCost: c.BCryptWorkFactor,
}

return compose.Compose(
fc,
store,
Expand All @@ -91,6 +96,7 @@ func newOAuth2Provider(c *config.Config, km jwk.Manager) fosite.OAuth2Provider {
compose.OAuth2AuthorizeExplicitFactory,
compose.OAuth2AuthorizeImplicitFactory,
compose.OAuth2ClientCredentialsGrantFactory,
oauth2.JWTBearerGrantFactory,
compose.OAuth2RefreshTokenGrantFactory,
compose.OpenIDConnectExplicitFactory,
compose.OpenIDConnectHybridFactory,
Expand Down
16 changes: 16 additions & 0 deletions generate-mocks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

PROJECT_ROOT=github.com/ory/hydra
MOCKS_DIR=internal/mocks

mockgen -package internal -destination $MOCKS_DIR/fosite_access_token_strategy.go github.com/ory/fosite/handler/oauth2 AccessTokenStrategy
mockgen -package internal -destination $MOCKS_DIR/fosite_access_token_storage.go github.com/ory/fosite/handler/oauth2 AccessTokenStorage
mockgen -package internal -destination $MOCKS_DIR/fosite_access_request.go github.com/ory/fosite AccessRequester
mockgen -package internal -destination $MOCKS_DIR/fosite_client.go github.com/ory/fosite Client
mockgen -package internal -destination $MOCKS_DIR/hydra_key_manager.go github.com/ory/hydra/jwk Manager

# See https://github.com/golang/mock/issues/30
find $MOCKS_DIR -type f -exec sed -i.bak "s,$PROJECT_ROOT/vendor/,,g" {} \;
rm -rf $MOCKS_DIR/*.bak

goimports -w $MOCKS_DIR/
8 changes: 6 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ import:
- clientcredentials
- package: gopkg.in/yaml.v2
- package: github.com/mohae/deepcopy
- package: github.com/golang/mock
version: ^1.0.0
subpackages:
- gomock
testImport:
- package: github.com/bmizerany/assert
- package: github.com/ory/dockertest
183 changes: 183 additions & 0 deletions internal/mocks/fosite_access_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions internal/mocks/fosite_access_token_storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading