Try setting LOG_LEVEL=debug and check the hydra logs, it should give a bit more information. From high level it looks ok. What confuses me though is that you’re using the code although you’re requesting the access token directly.
Please also note that the implicit flow is old and discouraged, use the authorization code flow with PKCE instead!
time="2018-04-21T02:52:29Z" level=info msg="completed handling request" measure#http://localhost:8080.latency=6077600 method=GET remote="172.18.0.1:58232" request=/.well-known/jwks.json status=200 text_status=OK took=6.0776ms
time="2018-04-21T02:52:32Z" level=info msg="started handling request" method=GET remote="172.18.0.1:58234" request="/oauth2/auth?response_type=code+id_token&nonce=f4a8f2a948f918be37301b2a8ff75f69&state=4f0c2bcd727b08308d1538681a5b3b78&code_challenge=DQ2zD1Li_GseiSVa5fjqZHEmVKaYx4DKDdBNLFzTsoE&code_challenge_method=S256&client_id=desktop-consumer&scope=openid+email+profile+email&redirect_uri=omnicasa%3A%2F%2Flocalhost%2Fwinforms.client&response_mode=form_post&customer-id=602"
time="2018-04-21T02:52:32Z" level=error msg="An error occurred" debug=invalid_request error=invalid_request hint="Make sure that the various parameters are correct, be aware of case sensitivity and trim your parameters. Make sure that the client you are using has exactly whitelisted the redirect_uri you specified."
time="2018-04-21T02:52:32Z" level=debug msg="Stack trace: \ngithub.com/ory/hydra/vendor/github.com/ory/fosite.(*Fosite).NewAuthorizeRequest\n\t/go/src/github.com/ory/hydra/vendor/github.com/ory/fosite/authorize_request_handler.go:55\ngithub.com/ory/hydra/oauth2.(*Handler).AuthHandler\n\t/go/src/github.com/ory/hydra/oauth2/handler.go:411\ngithub.com/ory/hydra/oauth2.(*Handler).AuthHandler-fm\n\t/go/src/github.com/ory/hydra/oauth2/handler.go:119\ngithub.com/ory/hydra/vendor/github.com/julienschmidt/httprouter.(*Router).ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/julienschmidt/httprouter/router.go:299\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.Wrap.func1\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:41\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:24\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.middleware.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.(middleware).ServeHTTP-fm\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1918\ngithub.com/ory/hydra/cmd/server.(*Handler).rejectInsecureRequests\n\t/go/src/github.com/ory/hydra/cmd/server/handler.go:200\ngithub.com/ory/hydra/cmd/server.(*Handler).(github.com/ory/hydra/cmd/server.rejectInsecureRequests)-fm\n\t/go/src/github.com/ory/hydra/cmd/server/handler.go:113\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:24\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.middleware.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.(middleware).ServeHTTP-fm\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\ngithub.com/ory/hydra/vendor/github.com/meatballhat/negroni-logrus.(*Middleware).ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/meatballhat/negroni-logrus/middleware.go:136\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.middleware.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.(*Negroni).ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:73\ngithub.com/ory/hydra/vendor/github.com/rs/cors.(*Cors).Handler.func1\n\t/go/src/github.com/ory/hydra/vendor/github.com/rs/cors/cors.go:200\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1918\ngithub.com/ory/hydra/vendor/github.com/gorilla/context.ClearHandler.func1\n\t/go/src/github.com/ory/hydra/vendor/github.com/gorilla/context/context.go:141\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1918\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2619\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:1801\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:2337"
time="2018-04-21T02:52:32Z" level=info msg="completed handling request" measure#http://localhost:8080.latency=747500 method=GET remote="172.18.0.1:58234" request="/oauth2/auth?response_type=code+id_token&nonce=f4a8f2a948f918be37301b2a8ff75f69&state=4f0c2bcd727b08308d1538681a5b3b78&code_challenge=DQ2zD1Li_GseiSVa5fjqZHEmVKaYx4DKDdBNLFzTsoE&code_challenge_method=S256&client_id=desktop-consumer&scope=openid+email+profile+email&redirect_uri=omnicasa%3A%2F%2Flocalhost%2Fwinforms.client&response_mode=form_post&customer-id=602" status=302 text_status=Found took="747.5µs"
time="2018-04-21T02:52:32Z" level=info msg="started handling request" method=POST remote="172.18.0.1:58236" request=/oauth2/token
time="2018-04-21T02:52:32Z" level=info msg="completed handling request" measure#http://localhost:8080.latency=97272000 method=POST remote="172.18.0.1:58236" request=/oauth2/token status=200 text_status=OK took=97.272ms
time="2018-04-21T02:52:54Z" level=info msg="started handling request" method=GET remote="172.18.0.1:58232" request=/.well-known/openid-configuration
time="2018-04-21T02:52:54Z" level=info msg="completed handling request" measure#http://localhost:8080.latency=38300 method=GET remote="172.18.0.1:58232" request=/.well-known/openid-configuration status=200 text_status=OK took="38.3µs"
time="2018-04-21T02:52:54Z" level=info msg="started handling request" method=GET remote="172.18.0.1:58232" request=/.well-known/jwks.json
time="2018-04-21T02:52:54Z" level=info msg="Access denied" error=request_unauthorized reason="Token is expired, malformed or missing" request="&{rn:hydra:keys:hydra.openid.id-token:public get map[]}" scopes="[hydra.keys.get]"
time="2018-04-21T02:52:54Z" level=info msg="Access allowed" reason="The policy decision point allowed the request" request="&{rn:hydra:keys:hydra.openid.id-token:public get map[]}" subject=
time="2018-04-21T02:52:54Z" level=info msg="completed handling request" measure#http://localhost:8080.latency=2453300 method=GET remote="172.18.0.1:58232" request=/.well-known/jwks.json status=200 text_status=OK took=2.4533ms
time="2018-04-21T02:52:57Z" level=info msg="started handling request" method=GET remote="172.18.0.1:58234" request="/oauth2/auth?response_type=code+id_token&nonce=1f95527129faad193d885b2b130dbb72&state=cf7353743a39555ca503b783a888220b&code_challenge=2zNt9Jbm5ejwwcbc7lzdKMVszbSSI--DqkRDc9yn8AA&code_challenge_method=S256&client_id=desktop-consumer&scope=openid+email+profile+email&redirect_uri=omnicasa%3A%2F%2Flocalhost%2Fwinforms.client&response_mode=form_post&customer-id=602"
time="2018-04-21T02:52:57Z" level=error msg="An error occurred" debug=invalid_request error=invalid_request hint="Make sure that the various parameters are correct, be aware of case sensitivity and trim your parameters. Make sure that the client you are using has exactly whitelisted the redirect_uri you specified."
time="2018-04-21T02:52:57Z" level=debug msg="Stack trace: \ngithub.com/ory/hydra/vendor/github.com/ory/fosite.(*Fosite).NewAuthorizeRequest\n\t/go/src/github.com/ory/hydra/vendor/github.com/ory/fosite/authorize_request_handler.go:55\ngithub.com/ory/hydra/oauth2.(*Handler).AuthHandler\n\t/go/src/github.com/ory/hydra/oauth2/handler.go:411\ngithub.com/ory/hydra/oauth2.(*Handler).AuthHandler-fm\n\t/go/src/github.com/ory/hydra/oauth2/handler.go:119\ngithub.com/ory/hydra/vendor/github.com/julienschmidt/httprouter.(*Router).ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/julienschmidt/httprouter/router.go:299\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.Wrap.func1\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:41\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:24\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.middleware.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.(middleware).ServeHTTP-fm\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1918\ngithub.com/ory/hydra/cmd/server.(*Handler).rejectInsecureRequests\n\t/go/src/github.com/ory/hydra/cmd/server/handler.go:200\ngithub.com/ory/hydra/cmd/server.(*Handler).(github.com/ory/hydra/cmd/server.rejectInsecureRequests)-fm\n\t/go/src/github.com/ory/hydra/cmd/server/handler.go:113\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:24\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.middleware.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.(middleware).ServeHTTP-fm\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\ngithub.com/ory/hydra/vendor/github.com/meatballhat/negroni-logrus.(*Middleware).ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/meatballhat/negroni-logrus/middleware.go:136\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.middleware.ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:33\ngithub.com/ory/hydra/vendor/github.com/urfave/negroni.(*Negroni).ServeHTTP\n\t/go/src/github.com/ory/hydra/vendor/github.com/urfave/negroni/negroni.go:73\ngithub.com/ory/hydra/vendor/github.com/rs/cors.(*Cors).Handler.func1\n\t/go/src/github.com/ory/hydra/vendor/github.com/rs/cors/cors.go:200\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1918\ngithub.com/ory/hydra/vendor/github.com/gorilla/context.ClearHandler.func1\n\t/go/src/github.com/ory/hydra/vendor/github.com/gorilla/context/context.go:141\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1918\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2619\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:1801\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:2337"
time="2018-04-21T02:52:57Z" level=info msg="completed handling request" measure#http://localhost:8080.latency=1288600 method=GET remote="172.18.0.1:58234" request="/oauth2/auth?response_type=code+id_token&nonce=1f95527129faad193d885b2b130dbb72&state=cf7353743a39555ca503b783a888220b&code_challenge=2zNt9Jbm5ejwwcbc7lzdKMVszbSSI--DqkRDc9yn8AA&code_challenge_method=S256&client_id=desktop-consumer&scope=openid+email+profile+email&redirect_uri=omnicasa%3A%2F%2Flocalhost%2Fwinforms.client&response_mode=form_post&customer-id=602" status=302 text_status=Found took=1.2886ms
time="2018-04-21T02:54:03Z" level=info msg="started handling request" method=POST remote="172.18.0.1:58238" request=/oauth2/token
time="2018-04-21T02:54:03Z" level=info msg="completed handling request" measure#http://localhost:8080.latency=99288300 method=POST remote="172.18.0.1:58238" request=/oauth2/token status=200 text_status=OK took=99.2883ms
I still don’t understand that if I use Authorization Code Grant mean at native app must listen callback base on loopback url like: http://localhost:12345.
The port must register with callback but I want random port to avoid conflict exiting port so how to resolve this case?
time=“2018-04-21T02:43:11Z” level=error msg=“An error occurred” debug=“The client is not allowed to use the authorization_code grant type” error=invalid_grant
Your client is allowed to use the implicit flow, but the hybrid flow (requesting a token) needs the authorization_code grant type which you haven’t whitelisted in your client.
The second request fails because you did not specify a redirect/callback url
time=“2018-04-21T02:52:57Z” level=error msg=“An error occurred” debug=invalid_request error=invalid_request hint=“Make sure that the various parameters are correct, be aware of case sensitivity and trim your parameters. Make sure that the client you are using has exactly whitelisted the redirect_uri you specified.”
Actually, I try with this client tool and it work with Identity Server 4. On C# app run on Windows/Linux as .NET Core can’t handler schema callback url style so only user loopback url with random port only.
Sorry, I can’t help with specific OAuth2 or OpenID Connect implementations. My recommendation is to not use the implicit flow at all and instead use the Authorize Code Flow with PKCE.
The Implicit grant type is a simplified flow that can be used by public clients, where the access token is returned immediately without an extra authorization code exchange step.
It is generally not recommended to use the implicit flow (and some servers prohibit this flow entirely). In the time since the spec was originally written, the industry best practice has changed to recommend that public clients should use either the authorization code flow without the client secret, or use the PKCE extension instead.
More information can be found on the OAuth mailing list from: Redhat, Deutsche Telekom, and Smart Health IT.
Is it possible to have Authorize Code Flow with PKCE in hydra? It seems like development is going on. If there is any way to to include PKCE in hydra authorize code flow then please let me know.
Thanks for your reply. Can you please give any reference/doc how to use it in hydra Authorize Code flow with PKCE?
I found in https://www.ory.sh/docs/hydra/advanced link that PKCE can be enable by following way
But the issue is if I send the wrong key/code in code_verifier it still giving me the access token. So it seems like it’s not considering code_verifier.
May be I miss understood how PKCE flow works. Please advice.
It’s not possible for me to tell what’s going wrong without seeing the actual URLs or with a reproducible step by step guide. PKCE should work properly and has several tests that make sure that, if used correctly, it shouldn’t be possible to bypass PKCE.
Created a node application as a client. Everything worked as expected. Authorize URL generated >> Login page came up >> Authorize Page came up >> Got the Access token
Now I tried to create a client with PKCE (Note: I didn’t provide the client secret but after client creation it generated the client secret)
In my client app I added code_challenge in the auth config in the first call to Hydra server and code_verifier when requesting access token. Everything works fine I get the access token successfully. Here is the code.