@@ -7,10 +7,11 @@ import (
77 "crypto/x509"
88 "encoding/json"
99 "encoding/pem"
10- "github.com/go-jose/go-jose/v3/jwt"
1110 "strconv"
1211 "strings"
1312
13+ "github.com/go-jose/go-jose/v3/jwt"
14+
1415 "github.com/cloudentity/oauth2c/internal/oauth2"
1516 "github.com/grantae/certinfo"
1617 "github.com/pterm/pterm"
@@ -274,6 +275,39 @@ func LogJARM(request oauth2.Request) {
274275 }
275276}
276277
278+ func LogRequestObject (r oauth2.Request ) {
279+ var (
280+ request = r .URL .Query ().Get ("request" )
281+ requestClaims map [string ]interface {}
282+ token * jwt.JSONWebToken
283+ err error
284+ )
285+
286+ if silent {
287+ return
288+ }
289+
290+ if request != "" {
291+ if token , requestClaims , err = oauth2 .UnsafeParseJWT (request ); err != nil {
292+ pterm .Error .Println (err )
293+ } else {
294+ pterm .DefaultBox .WithTitle ("Request object" ).Printfln ("request = JWT-%s(payload)" , token .Headers [0 ].Algorithm )
295+ pterm .Println ()
296+ pterm .Println ("Payload" )
297+ LogJson (requestClaims )
298+ pterm .Println ()
299+
300+ if r .SigningKey != nil {
301+ LogKey ("Signing key" , r .SigningKey )
302+ }
303+
304+ if r .EncryptionKey != nil {
305+ LogKey ("Encryption key" , r .EncryptionKey )
306+ }
307+ }
308+ }
309+ }
310+
277311func LogAssertion (request oauth2.Request , title string , name string ) {
278312 var (
279313 assertion = request .Form .Get (name )
@@ -301,8 +335,15 @@ func LogAssertion(request oauth2.Request, title string, name string) {
301335 LogJson (claims )
302336 pterm .Println ("" )
303337
304- pterm .Println ("Key" )
305- switch key := request .Key .(type ) {
338+ LogKey ("Signing key" , request .SigningKey )
339+ }
340+
341+ func LogKey (name string , key interface {}) {
342+ var err error
343+
344+ pterm .Println (name )
345+
346+ switch key := key .(type ) {
306347 case * rsa.PrivateKey :
307348 p := bytes.Buffer {}
308349
@@ -333,6 +374,8 @@ func LogAssertion(request oauth2.Request, title string, name string) {
333374 pterm .FgGray .Printfln (p .String ())
334375 case []byte :
335376 pterm .FgGray .Println (string (key ))
377+ case string :
378+ pterm .FgGray .Println (key )
336379 }
337380
338381 pterm .Println ()
@@ -369,5 +412,7 @@ func LogSubjectTokenAndActorToken(request oauth2.Request) {
369412 }
370413 }
371414
372- pterm .Println ()
415+ if subjectToken != "" || actorToken != "" {
416+ pterm .Println ()
417+ }
373418}
0 commit comments