@@ -14,23 +14,21 @@ import (
14
14
"html/template"
15
15
"io"
16
16
"net/http"
17
+ "net/url"
17
18
"os"
18
19
"strconv"
19
20
"strings"
20
21
"time"
21
22
22
- openapi "github.com/ory/hydra-client-go/v2"
23
- "github.com/ory/hydra/v2/cmd/cliclient"
24
-
25
- "github.com/pkg/errors"
26
-
27
- "github.com/ory/graceful"
28
-
29
23
"github.com/julienschmidt/httprouter"
24
+ "github.com/pkg/errors"
30
25
"github.com/spf13/cobra"
31
26
"github.com/toqueteos/webbrowser"
32
27
"golang.org/x/oauth2"
33
28
29
+ "github.com/ory/graceful"
30
+ openapi "github.com/ory/hydra-client-go/v2"
31
+ "github.com/ory/hydra/v2/cmd/cliclient"
34
32
"github.com/ory/x/cmdx"
35
33
"github.com/ory/x/flagx"
36
34
"github.com/ory/x/pointerx"
@@ -132,7 +130,7 @@ var tokenUserResult = template.Must(template.New("").Parse(`<html>
132
130
<ul>
133
131
<li>Access Token: <code>{{ .AccessToken }}</code></li>
134
132
<li>Refresh Token: <code>{{ .RefreshToken }}</code></li>
135
- <li>Expires in : <code>{{ .Expiry }}</code></li>
133
+ <li>Expires at : <code>{{ .Expiry }}</code></li>
136
134
<li>ID Token: <code>{{ .IDToken }}</code></li>
137
135
</ul>
138
136
{{ if .DisplayBackButton }}
@@ -170,6 +168,7 @@ and success, unless if the --no-shutdown flag is provided.`,
170
168
audience := flagx .MustGetStringSlice (cmd , "audience" )
171
169
noShutdown := flagx .MustGetBool (cmd , "no-shutdown" )
172
170
skip := flagx .MustGetBool (cmd , "skip" )
171
+ responseMode := flagx .MustGetString (cmd , "response-mode" )
173
172
174
173
clientID := flagx .MustGetString (cmd , "client-id" )
175
174
if clientID == "" {
@@ -229,6 +228,9 @@ and success, unless if the --no-shutdown flag is provided.`,
229
228
if maxAge >= 0 {
230
229
opts = append (opts , oauth2 .SetAuthURLParam ("max_age" , strconv .Itoa (maxAge )))
231
230
}
231
+ if responseMode != "" {
232
+ opts = append (opts , oauth2 .SetAuthURLParam ("response_mode" , responseMode ))
233
+ }
232
234
233
235
authCodeURL := conf .AuthCodeURL (state , opts ... )
234
236
return authCodeURL , state
@@ -293,6 +295,7 @@ and success, unless if the --no-shutdown flag is provided.`,
293
295
r .GET ("/consent" , rt .consentGET )
294
296
r .POST ("/consent" , rt .consentPOST )
295
297
r .GET ("/callback" , rt .callback )
298
+ r .POST ("/callback" , rt .callbackPOSTForm )
296
299
297
300
if ! flagx .MustGetBool (cmd , "no-open" ) {
298
301
_ = webbrowser .Open (serverLocation ) // ignore errors
@@ -336,6 +339,7 @@ and success, unless if the --no-shutdown flag is provided.`,
336
339
cmd .Flags ().String ("token-url" , "" , "Usually it is enough to specify the `endpoint` flag, but if you want to force the token url, use this flag" )
337
340
cmd .Flags ().Bool ("https" , false , "Sets up HTTPS for the endpoint using a self-signed certificate which is re-generated every time you start this command" )
338
341
cmd .Flags ().Bool ("skip" , false , "Skip login and/or consent steps if possible. Only effective if you have configured the Login and Consent UI URLs to point to this server." )
342
+ cmd .Flags ().String ("response-mode" , "" , "Set the response mode. Can be query (default) or form_post." )
339
343
340
344
return cmd
341
345
}
@@ -566,6 +570,8 @@ func (rt *router) consentPOST(w http.ResponseWriter, r *http.Request, _ httprout
566
570
}
567
571
568
572
func (rt * router ) callback (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
573
+ defer rt .onDone ()
574
+
569
575
if len (r .URL .Query ().Get ("error" )) > 0 {
570
576
_ , _ = fmt .Fprintf (rt .cmd .ErrOrStderr (), "Got error: %s\n " , r .URL .Query ().Get ("error_description" ))
571
577
@@ -576,20 +582,18 @@ func (rt *router) callback(w http.ResponseWriter, r *http.Request, _ httprouter.
576
582
Hint : r .URL .Query ().Get ("error_hint" ),
577
583
Debug : r .URL .Query ().Get ("error_debug" ),
578
584
})
579
-
580
- rt .onDone ()
581
585
return
582
586
}
583
587
584
588
if r .URL .Query ().Get ("state" ) != * rt .state {
585
- _ , _ = fmt .Fprintf (rt .cmd .ErrOrStderr (), "States do not match. Expected %s, got %s\n " , * rt .state , r .URL .Query ().Get ("state" ))
589
+ descr := fmt .Sprintf ("States do not match. Expected %q, got %q." , * rt .state , r .URL .Query ().Get ("state" ))
590
+ _ , _ = fmt .Fprintln (rt .cmd .ErrOrStderr (), descr )
586
591
587
592
w .WriteHeader (http .StatusInternalServerError )
588
593
_ = tokenUserError .Execute (w , & ed {
589
594
Name : "States do not match" ,
590
- Description : "Expected state " + * rt . state + " but got " + r . URL . Query (). Get ( "state" ) ,
595
+ Description : descr ,
591
596
})
592
- rt .onDone ()
593
597
return
594
598
}
595
599
@@ -603,7 +607,6 @@ func (rt *router) callback(w http.ResponseWriter, r *http.Request, _ httprouter.
603
607
_ = tokenUserError .Execute (w , & ed {
604
608
Name : err .Error (),
605
609
})
606
- rt .onDone ()
607
610
return
608
611
}
609
612
@@ -623,7 +626,18 @@ func (rt *router) callback(w http.ResponseWriter, r *http.Request, _ httprouter.
623
626
BackURL : rt .serverLocation ,
624
627
DisplayBackButton : rt .noShutdown ,
625
628
})
626
- rt .onDone ()
629
+ }
630
+
631
+ func (rt * router ) callbackPOSTForm (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
632
+ if err := r .ParseForm (); err != nil {
633
+ http .Error (w , err .Error (), http .StatusBadRequest )
634
+ return
635
+ }
636
+ u := url.URL {
637
+ Path : r .URL .Path ,
638
+ RawQuery : r .PostForm .Encode (),
639
+ }
640
+ http .Redirect (w , r , u .String (), http .StatusFound )
627
641
}
628
642
629
643
type ed struct {
0 commit comments