@@ -330,12 +330,11 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
330330
331331 var algorithmRadios = $ ( 'input[name="algorithm"]' ) ,
332332 lastRestoredToken ;
333+ var tokenRadios = $ ( 'input[name="token-type"]' ) ;
333334
334335 function setJSONEditorContent ( jsonEditor , decodedJSON , selector ) {
335336 jsonEditor . off ( 'change' , refreshTokenEditor ) ;
336337
337-
338-
339338 if ( decodedJSON . result !== null && decodedJSON . result !== undefined ) {
340339 jsonEditor . setValue ( decodedJSON . result ) ;
341340 } else {
@@ -385,23 +384,18 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
385384 if ( window . matchMedia ( '(min-width: 768px)' ) . matches ) {
386385 autoHeightInput ( ) ;
387386 }
388-
389387 }
390388
391389 function selectDetectedAlgorithm ( alg ) {
392390 var $algRadio = $ ( '.algorithm input[value="' + alg + '"]' ) ;
393391 $algRadio . prop ( 'checked' , true ) ;
394392
395393 fireEvent ( $algRadio . get ( 0 ) ) ;
396-
397-
398394 }
399395
400396 function saveToStorage ( jwt ) {
401397 // Save last valid jwt value for refresh
402398 safeLocalStorageSetItem ( "jwtValue" , jwt ) ;
403-
404-
405399 }
406400
407401 function loadFromStorage ( cb ) {
@@ -452,8 +446,6 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
452446 }
453447 tokenEditor . on ( 'change' , tokenEditorOnChangeListener ) ;
454448 fireEvent ( secretElement ) ;
455-
456-
457449 }
458450
459451 function getFirstElementByClassName ( selector ) {
@@ -502,8 +494,6 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
502494 isBase64
503495 ) ;
504496
505-
506-
507497 var error = result . error ;
508498 result = result . result ;
509499 if ( ! error && result ) {
@@ -515,8 +505,6 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
515505 $ ( signatureElement ) . addClass ( 'invalid-token' ) ;
516506 signatureElement . innerHTML = '<i class="icon-budicon-501"></i> invalid signature' ;
517507 }
518-
519-
520508 }
521509
522510 function getKey ( algorithm , action ) {
@@ -529,8 +517,6 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
529517 } else {
530518 return action === 'sign' ? privateKeyElement . val ( ) : publicKeyElement . val ( ) ;
531519 }
532-
533-
534520 }
535521
536522 function getAlgorithm ( ) {
@@ -547,30 +533,43 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
547533 . filter ( '.' + algorithm )
548534 . show ( ) ;
549535
550- if ( getTrimmedValue ( tokenEditor ) === DEFAULT_HS_TOKEN &&
536+ if ( getTokenType ( ) === 'id_token' && getTrimmedValue ( tokenEditor ) === DEFAULT_HS_TOKEN &&
551537 algorithm === 'RS256' ) {
552538 setDefaultsForRSA ( ) ;
553- } else if ( getTrimmedValue ( tokenEditor ) === DEFAULT_RS_TOKEN &&
539+ } else if ( getTokenType ( ) === 'id_token' && getTrimmedValue ( tokenEditor ) === DEFAULT_RS_TOKEN &&
554540 algorithm === 'HS256' ) {
555541 setDefaultsForHMAC ( ) ;
556542 }
557-
558-
559543 }
560544
561545 function setDefaultsForRSA ( ) {
562546 tokenEditor . setValue ( DEFAULT_RS_TOKEN ) ;
563547
564548 $ ( '.jwt-signature textarea[name=public-key]' ) . val ( DEFAULT_PUBLIC_RSA ) ;
565549 $ ( '.jwt-signature textarea[name=private-key]' ) . val ( DEFAULT_PRIVATE_RSA ) ;
566-
567-
568550 }
569551
570552 function setDefaultsForHMAC ( ) {
571553 tokenEditor . setValue ( DEFAULT_HS_TOKEN ) ;
554+ }
572555
556+ function updateToken ( ) {
557+ var tokenType = getTokenType ( ) ;
558+ if ( document . location . hash ) {
559+ var qs = document . location . hash . slice ( 1 ) ;
560+ var d = { } ;
561+ qs = qs . split ( '&' ) ;
562+ qs . forEach ( function ( kv ) { kv = kv . split ( '=' ) ; d [ kv [ 0 ] ] = kv [ 1 ] ; } ) ;
573563
564+ if ( d [ tokenType ] ) {
565+ tokenEditor . setValue ( decodeURIComponent ( d [ tokenType ] ) ) ;
566+ return ;
567+ }
568+ }
569+ }
570+
571+ function getTokenType ( ) {
572+ return tokenRadios . filter ( ':checked' ) . val ( ) ;
574573 }
575574
576575 function validateKey ( ) {
@@ -588,17 +587,19 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
588587 } else {
589588 $textarea . addClass ( 'error' ) ;
590589 }
591-
592-
593590 }
594591
595592 updateAlgorithm ( ) ;
596593
597594 algorithmRadios . on ( 'change' , function ( ) {
598595 updateAlgorithm ( ) ;
599596 updateSignature ( ) ;
597+ } ) ;
600598
601-
599+ tokenRadios . on ( 'change' , function ( ) {
600+ updateToken ( ) ;
601+ updateAlgorithm ( ) ;
602+ updateSignature ( ) ;
602603 } ) ;
603604
604605 $ ( '.jwt-signature textarea[name="public-key"]' ) . on ( 'input' , updateSignature ) ;
@@ -629,10 +630,21 @@ FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n\
629630 var d = { } ;
630631 qs = qs . split ( '&' ) ;
631632 qs . forEach ( function ( kv ) { kv = kv . split ( '=' ) ; d [ kv [ 0 ] ] = kv [ 1 ] ; } ) ;
633+
634+ if ( d . access_token && d . id_token ) {
635+ // show token-type selector
636+ $ ( '.jwt-playground .selections .token-type' ) . show ( ) ;
637+ }
638+
632639 if ( d . id_token ) {
633640 tokenEditor . setValue ( decodeURIComponent ( d . id_token ) ) ;
634641 return ;
635642 }
643+
644+ if ( d . access_token ) {
645+ tokenEditor . setValue ( decodeURIComponent ( d . access_token ) ) ;
646+ return ;
647+ }
636648 }
637649
638650 loadFromStorage ( function ( jwt ) {
@@ -669,6 +681,14 @@ $(".debugger-jwt .algorithm select").change(function() {
669681$ ( ".debugger-jwt .algorithm select" ) . change ( function ( ) { var a = $ ( '.debugger-jwt .algorithm input[value="' + $ ( this ) . val ( ) + '"]' ) ; a . prop ( "checked" , ! 0 ) } )
670682// end 07012015
671683
684+ $ ( ".debugger-jwt .token-type select" ) . change ( function ( ) {
685+ $ ( '.debugger-jwt .token-type input[value="' + $ ( this ) . val ( ) + '"]' ) . parent ( ) . trigger ( "click" ) ;
686+ $ ( '.debugger-jwt .token-type input[value="' + $ ( this ) . val ( ) + '"]' ) . change ( ) ;
687+ } ) ;
688+
689+ $ ( ".debugger-jwt .token-type select" ) . change ( function ( ) { var a = $ ( '.debugger-jwt .token-type input[value="' + $ ( this ) . val ( ) + '"]' ) ; a . prop ( "checked" , ! 0 ) } )
690+
691+
672692// Fetch stargazers count for each repo from GitHub's API
673693$ ( '.stars' ) . each ( function ( idx , element ) {
674694 var $el = $ ( element ) ;
0 commit comments